Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load resource as byte array programmatically

I added image as file and set type as resource (see screenshot) How do I pull it out as byte array without using resx files, etc?

enter image description here

like image 808
katit Avatar asked Feb 28 '12 18:02

katit


2 Answers

If you dont use the image directly (i.e: from a control if your project is a Windows App) then you could:

1- change the file extension (i.e: *.jpg.data)

2- add the "image" to a resource file RESX

3- access the byte array using: Resources.PathToImages.ResxFileName.ImageName

Note: if you add the image with the extension unchanged the RESX compiler creates a Bitmap property instead of a byte[] property.

like image 200
Alex Pollan Avatar answered Sep 21 '22 14:09

Alex Pollan


The process is described in How to embed and access resources by using Visual C#.

Essentially it requires use of reflection, using the Assembly class.

Stream imageStream = 
            currentAssembly.GetManifestResourceStream("Resources.logo_foot.png");

See How to convert an Stream into a byte[] in C#? for details of how to get a byte[] from a Stream.

like image 25
Oded Avatar answered Sep 23 '22 14:09

Oded