0

I have an image of 512*512 bytes and I have its values stored in an array. Now I want to copy these values into an object of Image class, which is derived from GDIPlusBase class. The constructor only takes stream or file name as argument. How can I put the values into this object?

Poojan
  • 3,312
  • 4
  • 20
  • 23

1 Answers1

1

If possible, use the Bitmap-Class which is derived from Image. It got the constructor you want: http://msdn.microsoft.com/en-us/library/ms536315%28v=vs.85%29

P.S.: If you really use GDI and not GDI+ please clarify.

Knowleech
  • 1,013
  • 2
  • 9
  • 15
  • Thanks! I am using GDI+. I am able to load the image by passing a BYTE array, but I am getting a coloured image eventhough my image is a GrayScale. I am first loading the image from a file using OpenCV and then make a BYTE array from that Image and load it into Bitmap. I am using "PixelFormat8bppIndexed" as the pixel format. Do you why is this happening? – Poojan May 29 '12 at 03:37
  • Using this pixel format, the image will use a color palette and will use your bytes as indices into this color palette. I have no idea what the default colors would. Use "SetPalette" to set a color palette explicitly. For each index, set a color with the corresponding gray value. This should do the trick. Infos on how to use the Palette can be seen here: http://stackoverflow.com/a/6012668/552373 – Knowleech May 30 '12 at 15:11