1 Public voidRgbtobitmap (BYTE/*Custom Data IntPtr*/BitsintWidth/*the width of the image*/,intHeight/*the height of the image*/)2 intWidthstep = width*3;//The general default step is 3 times times the width3 intLendata = widthstep * height;//data length, length of 24-bit image data = width * Height4 intLen =0;//representative Length5 //bits image frame data6 byte[] buffer =New byte[Len];//creates a specified length of byte data7Marshal.Copy (Bits, buffer,0, buffer. Length);8 9 Ten /** * * * The following is the conversion of RGB data to a Bitmap object * * **/ One intStride = width *3; AGCHandle handle =gchandle.alloc (buffer, gchandletype.pinned); - intScan0 = (int) handle. Addrofpinnedobject (); -Scan0 + = (Height-1) *Stride; theSystem.Drawing.Bitmap Bitmap =NewSystem.Drawing.Bitmap (width, height,-Stride, SYSTEM.DRAWING.IMAGING.PIXELFORMAT.FORMAT24BPPRGB, (INTPTR) scan0); - handle. Free (); - /********************************************/ - + /** * * * The following code is displayed in real time on the image control of WPF * * * * **/ -IntPtr IP = bitmap. Gethbitmap ();//To create a GDI bitmap object from GDI + bitmap + ABitmapSource BitmapSource =System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap (IP, IntPtr.Zero, Int32rect.empty, at System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions ()); - -Image1. Source =BitmapSource; - /********************************************/ -Bitmap. Dispose ();//Bitmap Release - in /*using DELETEOBEJCT This function needs to import functions from Gdi32.dll - [System.Runtime.InteropServices.DllImport ("Gdi32.dll")] to Public static extern bool DeleteObject (IntPtr hobject);*/ +DeleteObject (IP);
C # converts RGB image format data to bitmap and Bitsource objects