Get the name of the picture?

if(pictureBox4.Image.ToString() == 
    ePRO_Decision_Tool.Properties.Resources.mod_onalertq.ToString())...

How to read the file name of an image loaded in a pictureBox (or from resources)?

+3
source share
6 answers

An image uploaded to PictureBoxis just an array of bytes, so to find out what the file name is, you must fill out the property Tag PictureBoxwhen any image is uploaded to it.

+9
source

The object Imagecontains only binary image data. You can manually set the Tag Imagefile name for the property (after creating the image).

PictureBox Load(), PictureBox ImageLocation .

pictureBox4.ImageLocation .

ImageLocation MSDN

+4

, , Image , .

+1

PictureBox.Image.Load(Image Path)

PictureBoc.Image = Image.FromFile(Image Path) ( Image.Load()), Image.ImageLocation null

PictureBox.Image.Load("Image Path");
string imagepath = PictureBox.Image.ImageLocation.ToString();
                  imagepath = imagepath.Substring(imagepath.LastIndexOf("\\"));
                  imagepath = imagepath.Remove(0, 1);
0
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);
    }
}
0

#:

string imgPath = pictureBox1.ImageLocation; 
string nameImage =imgPath.Substring(imgPath.LastIndexOf('\\')+1);
0

Source: https://habr.com/ru/post/1782003/


All Articles