Reputation: 9574
if(pictureBox4.Image.ToString() ==
ePRO_Decision_Tool.Properties.Resources.mod_onalertq.ToString())...
How to read name of image file loaded in pictureBox (or from resources)?
Upvotes: 7
Views: 31233
Reputation: 1
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(* .jpg; * .jpeg; * .png;)|* .jpg; * .jpeg; * .png;";
if(open.ShowDialog() == DialogResult.OK){
piturebox1.Image = new Bitmap(open.FileName);
String ImageName = Path.GetFileName(open.FileName);
}
Upvotes: 0
Reputation: 1
get Image name by click
String getImageName = pictureBox1.Name;
MessageBox.Show(getImageName);
Upvotes: 0
Reputation: 11
You can use this way to get name of picture in picture box:
System.IO.Path.GetFileName(PictureBox.ImageLocation);
Upvotes: 1
Reputation: 2040
here is a simple way to get image name from picture box in c#:
string imgPath = pictureBox1.ImageLocation;
string nameImage =imgPath.Substring(imgPath.LastIndexOf('\\')+1);
Upvotes: -1
Reputation: 11
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Title = "Images";
openFileDialog1.Filter = "JPG Image(*.jpg)|*.jpg|BMP Image(*.bmp)|*.bmp";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName.ToString() != "")
{
string imagePath = openFileDialog1.FileName.ToString();
string imagepath = imagePath.ToString();
imagepath = imagepath.Substring(imagepath.LastIndexOf("\\"));
imagepath = imagepath.Remove(0, 1);
}
}
Upvotes: 1
Reputation: 910
this Method just working with loading image by PictureBox.Image.Load(Image Path)
not working with load image directly from resource
not working with load image by PictureBoc.Image = Image.FromFile(Image Path)
because above methods(except Image.Load()
) making Image.ImageLocation
set to null
PictureBox.Image.Load("Image Path");
string imagepath = PictureBox.Image.ImageLocation.ToString();
imagepath = imagepath.Substring(imagepath.LastIndexOf("\\"));
imagepath = imagepath.Remove(0, 1);
Upvotes: 0
Reputation: 49271
An Image
object only contains the image's binary data. You can manually set the Tag
property of the Image
to contain the file name (After you've created the image).
If you load an image to the PictureBox
using the Load()
method, that will update the PictureBox
's ImageLocation
property to the file's path.
Then you can use pictureBox4.ImageLocation
for comparison.
ImageLocation on MSDN
Upvotes: 5
Reputation: 14874
The image loaded in PictureBox
is just an array of bytes,
so to find out what is the filename you must fill the Tag
property of PictureBox
when any image loaded in it.
Upvotes: 11
Reputation: 11903
I'm pretty sure there's no way, the Image class doesn't expose where it came from.
Upvotes: 1