0

Hello I have an array with a bunch of grayscale values

var test="...0,222,254,254,254,254,241,198,198,198,198,198,198,198,198,170,52...".Split(',');

And I want to create a bitmap with those values

int c = 1;
var bmp = new Bitmap(28, 28);          
for (int i = 0; i < 28; i++)
for (int j = 0; j < 28; j++)
{
  bmp.SetPixel(i, j, Color.FromArgb(Convert.ToInt32(test[c]), Convert.ToInt32(test[c]), Convert.ToInt32(test[c])));
  c++;
}

However when I try to save it to disk:

bmp.Save(@"E:\r\0.jpg",ImageFormat.Jpeg);

I get the Generic GDI+ error

I have tried

Checking file permissions

Changing ImageFormat

Cloning the bitmap

Gustavo Puma
  • 968
  • 12
  • 27

2 Answers2

2

Sorry but I just tried this and this works well.

        Bitmap bmp = new Bitmap(28, 28);

        int c = 0;
        for (int i = 0; i < 28; i++)
        {
            for (int j = 0; j < 28; j++)
            {
                bmp.SetPixel(i, j, Color.FromArgb(i, i, i));
            }
        }

        bmp.Save("test.jpg", ImageFormat.Jpeg);

Are you sure the problem is in save?

Salvatore Previti
  • 8,566
  • 28
  • 37
0

Ok, I'm a dumbass, the problem is that I was saving the file to a folder that did not exist, I thought it would be created.

Gustavo Puma
  • 968
  • 12
  • 27