根据图像编码示例here http://msdn.microsoft.com/en-us/library/ms748873.aspx#_imageformats我应该能够使用png位图编码器 http://msdn.microsoft.com/en-us/library/System.Windows.Media.Imaging.JpegBitmapEncoder.aspx对图像进行编码以保存为 jpeg 文件,但出现此编译错误:
错误CS1503:参数1:无法从“System.Windows.Controls.Image”转换为“System.Uri”
我没有看到一种方法(图像中的属性或方法)来获取System.Uri
从图像。
我缺少什么?
图像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 http://msdn.microsoft.com/en-us/library/hh855347.aspx)将 640 x 480 RBG 流传输至可写位图 http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx30 Fps(kinect彩色图像格式 http://msdn.microsoft.com/en-us/library/microsoft.kinect.colorimageformat.aspx是 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);
}