Issue: After rotating a picturebox image - the image not the pbx - a new image assigned to the pbx will not display or update. The rotated image remains displayed in the pbx. After several "days" of experimenting and searching SO and others, I cannot find a solution to this.
The simplified code below illustrates the issue. I am undoubtedly overlooking something very simple - the question is "what"?.
Running C# Winforms .Net 4.7.2 using Visual Studio in Win10 1909 v18363.778
private void btnOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog OpenFileDialog = new OpenFileDialog())
{
OpenFileDialog.Title = "Open Image...";
OpenFileDialog.Filter = "Image File (*.bmp; *.gif; *.jpg; *.jpeg; *.png; *.wmf)|*.*";
OpenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
{
srcImg = Image.FromFile(OpenFileDialog.FileName);
tmpImg = srcImg;
pbx1.Image = tmpImg;
}
}
}
private void btnRotate_Click(object sender, EventArgs e)
{
tmpImg.RotateFlip(RotateFlipType.Rotate90FlipNone);
pbx1.Image = tmpImg;
}
private void btnReset_Click(object sender, EventArgs e)
{
// following code will not load original source image to "pbx1.Image"
// the rotated image remains displayed...
pbx1.Image = null;
pbx1.Image = srcImg;
pbx1.Refresh();
}