How to get path of Properties.Resources.Image in .

2020-07-09 02:55发布

I included an image as a resource following this post: How to create and use resources in .NET

I am using PDFSharp library to create a PDF. The method to draw an image, requires the path of the image. How do I get the path of Properties.Resources.Image?

Or is there another way to do this?

标签: c# .net pdfsharp
3条回答
来,给爷笑一个
2楼-- · 2020-07-09 02:58

You can actually create an image, without saving it, using XImage.FromGdiPlusImage():

var image = XImage.FromGdiPlusImage(Properties.Resources.logo);
查看更多
神经病院院长
3楼-- · 2020-07-09 03:01

The Properties.Resources.Image is in-memory resource.

You can save Image to temp file and the get the path.

var path = Path.GetTempPath();
Properties.Resources.logo.Save(path);

Above uses Bitmap.Save

查看更多
一夜七次
4楼-- · 2020-07-09 03:12

As of PDFsharp/MigraDoc 1.50 beta 2 and newer you no longer need a path when using MigraDoc. It was already mentioned that PDFsharp does not need a filename, as images can be read from e.g. streams.

MigraDoc still requires a string. You encode the image data as a string (BASE64 format) and pass that string as a filename.

See also:
http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx

查看更多
登录 后发表回答