【发布时间】:2013-07-09 13:28:03
【问题描述】:
根据图像编码示例here,我应该可以使用JpegBitmapEncoder 对图像进行编码以保存为jpeg 文件,但出现此编译错误:
错误 CS1503:参数 1:无法从“System.Windows.Controls.Image”转换为“System.Uri”
我看不到从 Image 中获取 System.Uri 的方法(Image 中的属性或方法)。
我错过了什么?
Image xaml 代码是
<Image Name="ColorImage"/>
SaveImage C# 是
...
SaveImage(ColorImage, path);
...
private void SaveImage(Image image, string path)
{
var jpegEncoder = new JpegBitmapEncoder();
jpegEncoder.Frames.Add(BitmapFrame.Create(image));
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
jpegEncoder.Save(fs);
}
}
下面的代码(主要取自 kinect-sdk)以 30 Fps 将 640 x 480 RBG 流式传输到 WriteableBitmap(kinect ColorImageFormat 是 RgbResolution640x480Fps30)。
using (var colorImageFrame = allFramesReadyEventArgs.OpenColorImageFrame())
{
if (colorImageFrame == null) return;
var haveNewFormat = currentColorImageFormat != colorImageFrame.Format;
if (haveNewFormat)
{
currentColorImageFormat = colorImageFrame.Format;
colorImageData = new byte[colorImageFrame.PixelDataLength];
colorImageWritableBitmap = new WriteableBitmap(
colorImageFrame.Width,
colorImageFrame.Height, 96, 96, PixelFormats.Bgr32, null);
ColorImage.Source = colorImageWritableBitmap;
}
// Make a copy of the color frame for displaying.
colorImageFrame.CopyPixelDataTo(colorImageData);
colorImageWritableBitmap.WritePixels(
new Int32Rect(0, 0, colorImageFrame.Width, colorImageFrame.Height),
colorImageData,
colorImageFrame.Width*Bgr32BytesPerPixel,
0);
}
【问题讨论】:
-
@Dumitru Chirutac:已经做到了。 JpegBitmapEncoder 链接在原帖中。
标签: c# wpf .net-4.5 jpegbitmapencoder