我正在尝试将视觉效果转换为 Ximage(在 pdf 上打印)。
目前我正在使用这个:
Dim img As XImage = XImage.FromFile(path.LocalPath)
但它需要我将它保存在我想使用它的硬盘上,但我不知道如何从视觉(在内存中)创建图像并将其加载。
Dim img As XImage = XImage.FromGdiPlusImage(myVisualAsImage)
如果您使用 PDFsharp 的 WPF 构建,您还可以使用:
public static XImage FromBitmapSource(BitmapSource image)
有几个类(包括 BitmapImage 和 WriteableBitmap)是从 BitmapSource 派生的,也可以在这里传递。
另见: http ://ryancdavidson.com/blog/2009/09/getting-and-using-the-pixels-of-your-visual-in-wpf/
vb.net - 克服 PDFSharp 1.5 中缺少的方法 FromGdiPlusImage
Function getTiffImage(sourceImage As Image, pageNumber As Integer) As XImage
Dim ms As MemoryStream
Dim returnImage As XImage
Try
ms = New MemoryStream()
Dim objGuid As Guid = sourceImage.FrameDimensionsList(0)
Dim objDimension As Imaging.FrameDimension = New Imaging.FrameDimension(objGuid)
sourceImage.SelectActiveFrame(objDimension, pageNumber)
sourceImage.Save(ms, Imaging.ImageFormat.Tiff)
returnImage = XImage.FromStream(ms)
Catch ex As Exception
returnImage = Nothing
End Try
Return returnImage