C#使用内存和指针方式将字节数组转换为Bitmap
作者:互联网
/// <summary> /// 指针方式转 /// </summary> /// <param name="Width">图像的宽</param> /// <param name="Height">图像的高</param> /// <param name="pointer">指针</param> private void Mono8ToBitmap(int Width,int Height,IntPtr pointer) { Bitmap bmp = new Bitmap(Width, Height, Width * 1, PixelFormat.Format8bppIndexed, pointer); ColorPalette cp = bmp.Palette; // init palette for (int i = 0; i < 256; i++) { cp.Entries[i] = Color.FromArgb(i, i, i); } // set palette back bmp.Palette = cp; pictureBox1.Invalidate(); } private void BytesToBitmap(int Width,int Height) { //一,内存复制方式: Bitmap myimg = new Bitmap(Width, Height, PixelFormat.Format8bppIndexed); BitmapData mydata; mydata = myimg.LockBits(new Rectangle(0, 0, myimg.Width, myimg.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); System.Runtime.InteropServices.Marshal.Copy(b, 0, mydata.Scan0, b.Length); myimg.UnlockBits(mydata); pictureBox1.Invalidate(); }
标签:字节,C#,Height,Width,int,mydata,Bitmap,myimg 来源: https://www.cnblogs.com/zxtang/p/15496340.html