.net - C#: Bitmap Creation using bytes array -


I am trying to make a bitmap image dynamic using the byte array using the following code

  Bitmap GetImage () {IntPtr ip = Marshal.AllocCoTaskMem (imagesize); // Some code to fill the IP image image = new bitmap (w, h, -tride, pixel format.form 24bprgb, (intpTR) (ip. Toint32 () + imedis - stride); Martial Freakoscus (IP); // Comment this line to return line work; } ZeroView Image () {Image IMG = Gate Image (); Img.save ("test.bmp"); // img.Dispose it fail (); }  

Now my problem is that I want to return a bitmap, but at the same time I do not want to place the IP pointers as a memory allotted leak. It is never free, how can I return the image created with the bytes array and how to do the memory without releasing the caller of the GetImage () function.

The easiest way to create a bitmap may be (though I use a normal Byte [] and then using the defined block by using AllocCoTaskMem ), and then an second Bitmap create a second bitmap, then use the graphics.Dream image by using the first bitmap to have the contents of the other bitmap other Call to effectively copy Graphics.FromImage . Then you can call Disk on the first bitmap, release the memory, and use another bitmap, which is basically a copy.

This may be a more effective way to do this if you are more efficient with image accessories, but if you are looking for a way to work it, this is a starting point Edit: Zair's comment makes it really easy to use things Constructor: using bitmap original = new bitmap (...) ) {Bitmap copy = new bitmap (original image); // Then return "copy" to your method, and you can release // memory


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -