privateBitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap) { BitmapImage bitmapImage=newBitmapImage();using(System.IO.MemoryStream ms =newSystem.IO.MemoryStream()) { bitmap.Save(ms, bitmap.RawFormat); bitmapImage.BeginInit(); bitmapImage.StreamSource=ms; bitmapImage.CacheOption=B...
bitmapImage.UriSource=newUri(szPath);//szPath为图片的全路径bitmapImage.EndInit(); bitmapImage.Freeze(); image1.Source= bitmapImage; 1. 2. 3. 4. 5. 6. 7. 二、Bitmap转BitmapImage 先将Bitmap储存成memorystream,然后指定给BitmapImage privateBitmapImage BitmapToBitmapImage(System.Drawing...
enc.Frames.Add(BitmapFrame.Create(bitmapImage)); enc.Save(outStream); Bitmap bitmap =newBitmap(outStream);returnnewBitmap(bitmap); } } RenderTargetBitmap –> BitmapImage // RenderTargetBitmap --> BitmapImagepublicstaticBitmapImageConvertRenderTargetBitmapToBitmapImage(RenderTargetBitmap wbm...
private BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap) { BitmapImage bitmapImage = new BitmapImage();using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { bitmap.Save(ms, bitmap.RawFormat);bitmapImage.BeginInit();bitmapImage.StreamSource = ms;bitmapImage.Cac...
Image是显示图片的控件,若要显示一张Bitmap的图片,必须转换成ImageSouce,并赋值给Souce,有如下几种方式: A: private ImageSource ToBitmapSourceA(Bitmap bitmap) { MemoryStream stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Bmp); ...
// 将指纹字节数组转换为Bitmap对象 public Bitmap ByteArrayToBitmap(byte[] byteArray) { using (MemoryStream stream = new MemoryStream(byteArray)) { return new Bitmap(stream); } } 接下来,将Bitmap对象转换为BitmapSource对象。BitmapSource是WPF中用于表示图像的类。可以使用System.Windows.Media.Ima...
ImageSource –> Bitmap BitmapImage和byte[]相互转换。 byte[] –> Bitmap StackOverflow上有很多解决方案,这里选择了试过可行的方法: Bitmap和BitmapImage相互转换 谷歌上搜关键字 C# WPF Convert Bitmap BitmapImage // Bitmap --> BitmapImagepublicstaticBitmapImageBitmapToBitmapImage(Bitmap bitmap){...
bitmap) { //Bitmap bitmap = icon.ToBitmap(); IntPtr hBitmap = bitmap.GetHbitmap(); ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); if (!DeleteObject(hBitmap)) { ...
1:设置Iamge的Source属性的时候,在前台Xaml文件可以设置为路径的字符串格式,但是在后台cs文件需要构造一个Bitmap的实例赋值给Image的Source属性,还要注意实例化Uri类的时候需要传进来一个UriKind.Relative的枚举。如下: Uri uri =newUri("/Images/"+ curImage,UriKind.Relative); BitmapImage bitmap =newBitmapImage...
public BitmapSource Convert(System.Drawing.Bitmap bitmap){ var bitmapData = bitmap.LockBits( new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap....