Faced such a problem "System.ArgumentException", while writing an envelope from an image (.jpg) in a text file with a picture (ASCII). Did according to the instructions (https://www.bilibili.com/video/av5862027/)
For the second or third day I try to solve this problem.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
namespace ayy
{
class Program
{
static void Main(string[] args)
{
FileStream stream = new FileStream(@"meme.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
for (int imageNumber = 0; imageNumber <= 7600; imageNumber++)
{
string url = @"C:\Users\Admin\source\repos\badapple\ayy\ba\ba";
if (imageNumber < 10)
{
url += "00000";
}
else if (imageNumber < 100)
{
url += "0000";
}
else if (imageNumber < 1000)
{
url += "000";
}
else
{
url += "00";
}
url += imageNumber.ToString() + ".jpg";
Bitmap image = new Bitmap(url, true);
for (int y = 0; y < image.Height; y++)
{
string str = "";
for (int x = 0; x < image.Width; x++)
{
Color pixel = image.GetPixel(x, y);
if (pixel.R > 200)
{
str += "#";
}
else
{
str += " ";
}
writer.WriteLine(str);
}
Console.WriteLine(url);
}
writer.Close();
}
}
}
}
Bitmap image = new Bitmap(url, true);with disposing or using theusingstatement is a one way street to anOutOfMemoryException