Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all
i want to get the name of the resource file of the image in the picture box control during the runtime

plz help
Posted

1 solution

If you loading the image using Load method of the PictureBox control then, You can find the name using picturebox1.ImageLocation.But if you embed it as resource file, the only thing you can access the image as Bitmap from the Resources class.

C#
Bitmap image = global::WindowsFormsApplication1.Properties.Resources.BugsBunny;


Or If your resources are embedded [^] in the assambly, then you can list them as follows

C#
Assembly assembly = Assembly.GetExecutingAssembly();
string[] resources = assembly.GetManifestResourceNames();
foreach (var resource in resources.Where(r => r.EndsWith(".png") || r.EndsWith(".jpg")))
{
    // Do somthing
}



I hope this solve your problem.
 
Share this answer
 
v2
Comments
Sabry1905 8-May-11 1:55am    
thx for your help, but un unfortunately this is not what I need exactly, in your code "BugsBunny" is the name of the resource which is already known for you, but in my case I don’t know the name of the resource at the runtime, in the runtime I should ask the picture box control or the application to tell me what is the name of the resource that being used by the picture box,

Anyway let me tell you why I want to do that, i want to compare to images at runtime without doing any image processing

In my case I am comparing to images in two picture boxes,
i assume that if both of the two picture boxes refer to the same resource then the two images are identical
Wonde Tadesse 8-May-11 11:40am    
Take a look at this code project article. It may help you http://www.codeproject.com/KB/dotnet/embeddedresources.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900