c# - System::Drawing::Bitmap to unsigned char * -


i have c# .net library grabs frames camera. need send frames native application takes images unsigned char*.

i take frames system::drawing::bitmap.

so far can retrieve byte[] bitmap. test done image of resolution 400*234, should getting 400*234*3 bytes 24bpp rgb image requires.

however, i'm getting byte[] of size 11948.

this how convert bitmap byte[]:

private static byte[] imagetobyte(bitmap img) {     imageconverter converter = new imageconverter();     return (byte[])converter.convertto(img, typeof(byte[])); } 

what proper way convert system::drawing::bitmap rgb unsigned char*?

this has done using lockbits method, here code example:

    rectangle rect = new rectangle(0, 0, m_bitmap.width, m_bitmap.height);     bitmapdata bmpdata = m_bitmap.lockbits(rect, imagelockmode.readonly,         m_bitmap.pixelformat);      intptr ptr = bmpdata.scan0;     int bytes = math.abs(bmpdata.stride) * m_bitmap.height;     byte[] rgbvalues = new byte[bytes];     marshal.copy(ptr, rgbvalues, 0, bytes);     m_bitmap.unlockbits(bmpdata);     gchandle handle = gchandle::alloc(rgbvalues, gchandletype::pinned);     unsigned char * data = (unsigned char*) (void*) handle.addrofpinnedobject();     //do whatever data 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -