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

旧巷老猫 提交于 2019-12-05 23:19:46

问题


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?


回答1:


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




回答2:


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

var image = XImage.FromGdiPlusImage(Properties.Resources.logo);



回答3:


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



来源:https://stackoverflow.com/questions/14265492/how-to-get-path-of-properties-resources-image-in-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!