代码中的行 wb.SaveJpeg 生成错误:System.Windows.Media.Imaging.WriteableBitmap'不包含'SaveJpeg'的定义,并且没有扩展方法'SaveJpeg'接受'System.Windows.Media'类型的第一个参数.Imaging.WriteableBitmap' 可以找到
我已将其列为参考:PresentationCore、PresentaionFramework、System.Windows.Forms、WindowsBase。
BitmapImage image = CaptureImageFromClipBoard();
WriteableBitmap wb = new WriteableBitmap(image);
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fs = isf.CreateFile(path + "\\" + filename + ".jpg"))
{
wb.SaveJpeg(fs, wb.PixelWidth, wb.PixelHeight, 10, 100);
}
}
这是 CaptureImageFromClipBoard 的方法:
static public BitmapImage CaptureImageFromClipBoard()
{
var img = new System.Windows.Controls.Image();
var imgsrc = Clipboard.GetImage();
img.Source = new FormatConvertedBitmap(imgsrc, PixelFormats.Bgr32, null, 0);
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
MemoryStream memoryStream = new MemoryStream();
BitmapImage bImg = new BitmapImage();
encoder.Frames.Add(BitmapFrame.Create(imgsrc));
encoder.Save(memoryStream);
bImg.BeginInit();
bImg.StreamSource = new MemoryStream(memoryStream.ToArray());
bImg.EndInit();
memoryStream.Close();
return bImg;
}