c# - How can I load a generated Bitmap into a PictureBox? -
There are many pictures that seem to be out of the question, but I have not found any deal with changing the contents of a film The bitmap was not loaded from the file just for that.
My application takes an array of bytes and generates a bitmap from them, I really do not want to leave the file as an intermediate processing step.
Because it is an array of bytes, and is not a 2-byte word, I need to create an indexed bitmap with a grayscale palette. / P>
I then converted the indexed bitmap to normal (24 bit RGB).
This is the code that is causing me an error:
PhotoBoxA 1 Image = (system. Drawing image) BMP 2;
When I look at the form (tries to draw a picture), the thread will stop execution with a message: "Invalid parameter on the system, drawing.image.get_ref format ( ) "
What am I doing wrong? How do I create a safe bitmap for a picture box?
This is what makes "BMP 2":
// is making a bitmap from the array system. Drawing Bitmap BMP 1 = new system Drawing Bitmap (100, 100, 100, System Drawing Imaging Pixel Format.format 8 BPP Indexed, MyInTTP); // is making a proper indexed palette system. Drawing Imaging Colorepetrate grapelet = BMP1. Palette; For (int i = 0; i & lt; grapelate.in.in langati; i ++) {GrayPalet. Entries [I] = Color FARBB (I, I, I); } Bmp1.Palette = Grapelet; // Creating 24 BPRGB Bitmap for a non-indexed, PictBoob compatibility system. Drawing. Bitmap BMP2 = new bitmap (BMP1 width, BMP 1.high, system, drawing.imaging.pixelformat.form24bpRGB); Graphics GR = Graphics.Fremight (BMP2); Gr.DrawImage (bmp1, 0, 0); Gr.Dispose ();
If I use BMP 1 then Save (@ "testfile.bmp") I get a completely acceptable bitmap that appears to be without any discrepancy.
Why can not I use my bitmap as my picture.Picture? Do I need to make changes before loading the new bitmap in the extra parameters of the picture box?
Well, I got the problem from what I was doing.
I will try to explain what was wrong, but as a non-guru I am not sure how accurate I am.
Apparently setting the image in a photo box does not copy memory anywhere in my application (some tasks that I have shown away from the code snippet), by settling the "bmp1" variable having had.
I did not know that the memory associated with BMP 1 was the same memory everywhere the function passes it, and it destroys the invalid parameters on "system.Drawing.Image.get_RawFormat ()". was raised. I think it does this because every time the painting box is rediscovered, it uses its "image" property, well it attracts, because I'm settling the memory associated with the "image" property So I was working properly in the Photobookant event.
I just hope that I never have memory leaks. Setting up any bitmaps I have been dealing with.
Comments
Post a Comment