首先得到ImageSource对象_imagesource System.IO.MemoryStream ms=newSystem.IO.MemoryStream(); BmpBitmapEncoder encoder=newBmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapSource)_imagesource)); encoder.Save(ms); Bitmap bp=newBitmap(ms); ms.Close(); 转自:http://Www.CnBlogs.C...
1:设置Iamge的Source属性的时候,在前台Xaml文件可以设置为路径的字符串格式,但是在后台cs文件需要构造一个Bitmap的实例赋值给Image的Source属性,还要注意实例化Uri类的时候需要传进来一个UriKind.Relative的枚举。如下: Uri uri =newUri("/Images/"+ curImage,UriKind.Relative); BitmapImage bitmap =newBitmapImage...
5.从ImageSource转换成Bitmap,是从ImageSource中取出UriSource.LocalPath,然后使用 new Bitmap(FileName)的方法获取。其他的方法我还没有找到, // System.Windows.Controls.Image ImgUserHeadFaceCutEdit; string str1 = ((BitmapImage)(ImgUserHeadFaceCutEdit.Source)).UriSource.AbsolutePath;// 此路径new Bit...
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...
BitmapImage转换为byte[]: public static byte[] BitmapImageToByteArray(BitmapImage bmp) { byte[] byteArray = null; try { Stream sMarket = bmp.StreamSource; if (sMarket != null && sMarket.Length > 0) { //很重要,因为Position经常位于Stream的末尾,导致下面读取到的长度为0。
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....
varbitmapSource=imageSourceasBitmapSource;if(bitmapSource!=null){varencoder=newJpegBitmapEncoder()...
您可以简单地设置Source属性设置为以下代码中的BitmapImage:image.Source = bitmap;...
1. 使用Source属性显示图片 UI 添加Image控件 <Image x:Name="ImageViewer1" Height="100" Width="200"/> 后台代码给Source属性赋值 ImageViewer1.Source = new BitmapImage(new Uri(@"Images\VS2015.jpg", UriKind.Relative)); 效果图如下: 动态切换Source 指定的文件,使用OpenFileDialog 类来选择图片源文件...