Answer the question
In order to leave comments, you need to log in
How to get the path to an image loaded in a PictureBox?
Hello, I am making a program for working with images in WIndows Forms c#. I am using MDI. I would like to know how to get the path to the loaded image from OpenFileDilaog ? It is necessary to save the image along the same path.
Image opening code
private void openImageToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openfile.ShowDialog() == DialogResult.OK)
{
try//Попытаемся открыть файл
{
bmp = new Bitmap(((PictureBox)ActiveMdiChild.Controls["pictureBox"]).Image = Image.FromFile(openfile.FileName), childForm.pictureBox.Width, childForm.pictureBox.Height);
((PictureBox)ActiveMdiChild.Controls["pictureBox"]).Image = bmp;
imageDirect = ((PictureBox)ActiveMdiChild.Controls["pictureBox"]).ImageLocation;
MessageBox.Show(imageDirect, "Test", MessageBoxButtons.OK);
}
catch
{
MessageBox.Show("Невозможно открыть файл!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
((PictureBox)ActiveMdiChild.Controls["pictureBox"]).Image.Save(((PictureBox)ActiveMdiChild.Controls["pictureBox"]).ImageLocation);
MessageBox.Show("Файл Сохранен успешно!");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question