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);