Reputation: 161
I have two PictureBoxes
where I want to show an image in the first and then a rotated version in the second. The code I would believe should work does act strange however, as the image is rotated in both PictureBoxes
:
Image im = Image.FromFile(D:\somefolder\picture.jpg");
pictureBox1.Image = im;
Image im_rot = im;
//Image im_rot = Image.FromFile(D:\somefolder\picture.jpg");
im_rot.RotateFlip(RotateFlipType.Rotate270FlipNone);
pictureBox2.Image = im_rot;
If I replace line 3 with line 4 it works, but why doesn't it work the other way?
Upvotes: 0
Views: 42
Reputation: 4755
The way your code is currently written, you're assigning the same object to both variables. This means that when you operate on either one, it's changing the same object in memory. With the alternate code you have commented out, you create a new, distinct object which is assigned to each variable.
Upvotes: 3