0

i have an excel document in which images get added on to. Some of my images loads correctly and some of them are been rotated on it own.

this is part of my code

if (!base64Image.IsNullOrEmpty())
                {
                    int ColumnCount = 3;


                    string x = base64Image.Substring(base64Image.LastIndexOf(',') + 1);
                    var bitmapData = Convert.FromBase64String(x);
                    var streamBitmap = new System.IO.MemoryStream(bitmapData);
                    var bitmap = new Bitmap((Bitmap)Image.FromStream(streamBitmap,true));
                    var image = bitmap;
                    ExcelPicture picture = null;
                    if (image != null)
                    {
                        picture = excelWorksheet.Drawings.AddPicture("Hello", image);
                        picture.From.Column = ColumnCount;
                        picture.From.Row = rowCounter+1;
                        picture.SetSize(150, 150);
                    }
                }
                stream = new MemoryStream(excelPackage.GetAsByteArray());
                excelToSend = stream.ToArray();
                stream.Close();

i tried to set no rotation on the image variable like:

 var image = bitmap;
                    image.RotateFlip(RotateFlipType.RotateNoneFlipNone);

but nothing happens.

i did researching online and they mentioned it could be something to do with orientation tags. also tried example. But my propertyitems is always empty

this is what the bitmap variable looks like when the image is been read from the stream enter image description here

deanpillow
  • 121
  • 1
  • 10
  • Just for the sake of trying, have you try to `var image = image.RotateFlip(RotateFlipType.RotateNoneFlipNone);` – Camadas Oct 14 '22 at 12:39
  • @Camadas but i am assigning my bitmap variable to the image, if i do the above the image wont have any value with in it to check rotation. or am i misunderstanding? – deanpillow Oct 14 '22 at 12:48
  • I told you for the sake of trying :) Was trying to see if I remember of a similar case that I did have, only after assigning to a new variable that the changes did occur bu't don't remember, that's why i was saying for the sake of trying :P – Camadas Oct 14 '22 at 13:48
  • Does this answer your question? [Get Image Orientation and rotate as per orientation](https://stackoverflow.com/questions/27835064/get-image-orientation-and-rotate-as-per-orientation) – BurnsBA Oct 14 '22 at 14:12
  • @BurnsBA i have also tried that,i set useEmbeddedColorManagement to true but i still dont get any data returned in my property items and the image is still be rotated. attached a screen shot of how the bitmap looks – deanpillow Oct 14 '22 at 14:23

0 Answers0