1

代码中的行 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;
}
4

1 回答 1

0

我建议这样做-注意:未经测试,从内存和原始帖子中键入...

static public void SaveCapturedImageFromClipBoard(Stream target)
{
    var img = new System.Windows.Controls.Image();
    var imgsrc = Clipboard.GetImage();
    img.Source = new FormatConvertedBitmap(imgsrc, PixelFormats.Bgr32, null, 0);

    JpegBitmapEncoder encoder = new JpegBitmapEncoder();

    encoder.Frames.Add(BitmapFrame.Create(imgsrc));
    encoder.Save(target);
}

using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
     using (var fs = isf.CreateFile(path + "\\" + filename + ".jpg"))
     {
         SaveCapturedImageFromClipBoard(fs);
     }
}
于 2013-03-14T01:59:12.300 回答