这是问题所在。我想从本地驱动器打开一个文件,然后将其转换为WritableBitmap,这样我就可以对其进行编辑。但问题是,我不能从Uri或类似的东西创建WritableBitmap。此外,我知道如何在BitmapImage中打开文件,但我不知道如何以WritableBitmap打开文件。有没有办法将文件直接打开到WritableBitmap中,如果没有,有没有办法将BitmapImage转换成WritableBitmap?谢谢你们。
发布于 2010-11-23 17:00:58
您可以将图像文件加载到BitmapImage中,并将其用作WriteableBitmap的源
BitmapImage bitmap = new BitmapImage(new Uri("YourImage.jpg", UriKind.Relative));
WriteableBitmap writeableBitmap = new WriteableBitmap(bitmap);发布于 2010-11-23 17:00:17
我不是专家,也不能立即访问智能感知之类的东西,但这里有...
var fileBytes = File.ReadAllBytes(fileName);
var stream = new MemoryStream(fileBytes);
var bitmap = new BitmapImage(stream);
var writeableBitmap = new WritableBitmap(bitmap);即使这不是一个完美的例子,这也应该足以为您指明正确的方向。希望如此。
发布于 2015-07-16 12:41:24
在Silverlight5中,您可以使用以下方法从本地磁盘打开文件,并将其转换为BitmapImage并使其进入WriteableBitmap;
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = false;
dlg.ShowDialog();
byte[] byteArray = new byte[] { };
if (dlg.File == null) return;
BitmapImage bi = new BitmapImage();
bi.CreateOptions = BitmapCreateOptions.None;
// bi.UriSource = new Uri(@"C:\Users\saw\Desktop\image.jpg", UriKind.RelativeOrAbsolute);
bi.SetSource(dlg.File.OpenRead());
WriteableBitmap eb=new WriteableBitmap(bi);尝试创建WriteableBitmap时,设置新Uri出现错误(未将对象引用设置为对象的实例)
https://stackoverflow.com/questions/4254225
复制相似问题