1

Recently I learned how to save an image as bytes (RGB values in a text file), and now I'd like to know how to create a perfectly valid image from array of RGB values.

Community
  • 1
  • 1
user1306322
  • 8,561
  • 18
  • 61
  • 122
  • 1
    Can't you use the [constructor that takes dimensions](http://msdn.microsoft.com/en-us/library/7we6s1x3.aspx), read your files, and call `SetPixel` on each of the pixels? – Sergey Kalinichenko Apr 15 '12 at 11:52
  • I don't have any files, I only have a 2d array of pixels' RGB values, what do I do next? (edit: didn't see the second comment, trying now) – user1306322 Apr 15 '12 at 11:56

1 Answers1

2

You can use the approach mentioned by @dasblinkenlight:

int width = 1; // read from file
int height = 1; // read from file
var bitmap = new Bitmap(width, height, PixelFormat.Canonical);

for (int y = 0; y < height; y++)
   for (int x = 0; x < width; x++)
   {
      int red = 0; // read from array
      int green = 0; // read from array
      int blue = 0; // read from array
      bitmap.SetPixel(x, y, Color.FromArgb(0, red, green, blue));
   }
Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99