我从本地图像文件创建一个位图图像覆盖另一个位图,但是当指定文件URI时,我得到一个System.UriFormatException
,我不能理解,因为该图像存储在项目中名为图像的文件夹中似乎是正确的。这是我如何指定URI new Uri("Images/boxbag.png")
。有人可以解释为什么我得到这种格式异常,是文件路径问题还是我设置URI的方式。如何将URI路径添加到位图图像?
这是下面这应该澄清事情的完整方法更多:
void myKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e) {
using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) {
if (colorFrame == null) return;
byte[] colorData = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(colorData);
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
//drawing image overlay to video feed
var drawingVisual = new DrawingVisual();
var drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawImage(BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel),
new Rect(new Size(colorFrame.Width, colorFrame.Height)));
var overlayImage = new BitmapImage(new Uri("Images/boxbag.png"));
drawingContext.DrawImage(overlayImage, new Rect(12, 12, overlayImage.Width, overlayImage.Height));
drawingContext.Close();
var mergedImage = new RenderTargetBitmap(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Pbgra32);
mergedImage.Render(drawingVisual);
KinectVideo.Source = mergedImage;
}
}
你能举一个这样的代码示例吗? –
@BrianJ我又添了一句话。这个版本的构造函数假定绝对URI。 – AlexD
好吧我现在明白了,默认的URI是绝对的,这就是为什么它将一个相对URI作为参数抛出一个错误。 –