Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

pdfsharp

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?

like image 968
Crystal Avatar asked Jan 10 '13 19:01

Crystal


2 Answers

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

like image 71
Tilak Avatar answered Sep 25 '22 23:09

Tilak


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

var image = XImage.FromGdiPlusImage(Properties.Resources.logo);
like image 37
Mario S Avatar answered Sep 25 '22 23:09

Mario S