【发布时间】:2018-05-03 04:39:30
【问题描述】:
我正在开发一个应用程序,并且我想实现一个类似于 Microsoft Power Point 的分页系统的功能,在该系统旁边有一个您正在处理的工作表的较小图像。
我有以下函数可以渲染用户必须在其中工作的网格图像。
private void CreateImageOfPage()
{
int width = (int)this.WorkSheetViewModelList.Last().RootGrid.Width;
int height = (int)this.WorkSheetViewModelList.Last().RootGrid.Height;
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
renderTargetBitmap.Render(this.WorkSheetViewModelList.Last().RootGrid);
PngBitmapEncoder pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
Guid photoID = System.Guid.NewGuid();
String photolocation = "Temp/"+photoID.ToString() + ".png";
using (var filestream = new FileStream(photolocation, FileMode.Create))
encoder.Save(filestream);
Console.WriteLine(Path.GetFullPath(photoID.ToString() + ".png"));
}
我的问题是,如何获取、设置或格式化保存图像的路径以设置为 XAML 中的图像源?当前形式的路径如下所示:“D:\Project\bin\Debug\7fd77420-f62e-44e7-b206-b5ce19f01a9e.png”,它说它无法在这个位置获取文件(现在我只是复制了输出,但它应该是绑定的)。
如果我采取的路径不优雅,有没有其他方法可以做得更好,或者根本不将图像保存到磁盘?
谢谢!
【问题讨论】:
标签: c# wpf imagesource