c# - Can I safely use array of bytes in Bitmap in struct? -


i have following code, pixeldata byte array of raw pixeldata:

// pin pixeldata gc cannot move while use it. gchandle handle = gchandle.alloc(pixeldata, gchandletype.pinned);  intptr pixeldata2address = handle.addrofpinnedobject();  // stride size of 1 line in bmp. int stride = bitmap.width * samplesperpixel;  // copy pixeldata new bitmap. bitmap image = new bitmap(bitmap.width, bitmap.height, stride, pixelformat.format24bpprgb, pixeldata2address);  imagedata imagedata; imagedata.bitmap = image; imagedata.imagenumber = imagenumber;            // unpin pixeldata. handle.free(); 

my question is, can still use imagedata struct safely after have freed handle? on msdn read in constructor of bitmap:

the caller responsible allocating , freeing block of memory specified scan0 parameter. however, memory should not released until related bitmap released.

so understand long want use image need keep handle "unfreed". count imagedata.bitmap? or assignment operator in line imagedata.bitmap = image; making "deep copy" of bitmap?


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -