Question

I am trying to get image from FileDialog My code :

private void BtnAddImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog addImage = new OpenFileDialog();

            if (addImage.ShowDialog() == DialogResult.OK)
            {
                PbAddImage.Image = new Bitmap(addImage.FileName);
            }
            PbAddImage.Image.Save("C:\\Users\\musa\\Documents\\Hobby\\testUser.jpg");
        }

When i select images which height is bigger than width. (For example, width 1200 px , height 1600 px). In pictureBox i saw this image left rotated.But if image width is bigger than height , there is no problem.

And then i saved this image to file, in saved image there is no problem. It does not save as rotated.

How can i handle this issue ? Why images shows rotated ?

Edit : Here is my PbAddImage properties :

this.PbAddImage.Location = new System.Drawing.Point(157, 211);
this.PbAddImage.Name = "PbAddImage";
this.PbAddImage.Size = new System.Drawing.Size(112, 161);
this.PbAddImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.PbAddImage.TabIndex = 138;
this.PbAddImage.TabStop = false;
Was it helpful?

Solution

I've recreated everything you've put here and can't reproduce the issue, I'd say you must have some code somewhere rotating your PictureBox. I would suggest doing a Find All References on your PbAddImage to see if any code is rotating it that you're unaware of.

Sorry, I would have left a comment instead but don't have enough rep.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top