dotnet bitmap

2020-01-14 15:55:51 浏览数 (1)

bitmap

代码语言:javascript复制
using (MemoryStream ms = new MemoryStream(image))    //容易出现异常
{
	bmImage = new Bitmap(Image.FromStream(ms));
	ms.Close();
}

bitmapdata

代码语言:javascript复制
//PixelFormat设置错误会修改数据
BitmapData bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
Marshal.Copy(image, 0, bmData.Scan0, image.Length);
//bmpData.Scan0 = data;   不安全
bmImage.UnlockBits(bmpData);

bitmapsource

代码语言:javascript复制
IntPtr ip = pic.GetHbitmap();
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
	ip, IntPtr.Zero, Int32Rect.Empty,
	System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);

imageconver

代码语言:javascript复制
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
        Image img = (Image)converter.ConvertFrom(byteArrayIn);

0 人点赞