dotnet / dotnet/wpf

"BitmapImage.EndInit" causes an exception if "Rotation" and "DecodePixelWidth" is used with small images

Open
#5,663 3 comments 1 reaction 1 assignee Claimed by @singhashish-wpf View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/BitmapImageEndInit-causes-an-exceptio/1352982)._

---
[severity:It's more difficult to complete my work]
The following code causes the System.InvalidOperationException in the method "EndEdit" if the image file (here "img0010.jpg") is a small image:
[ShowErrorProject.zip] (https://aka.ms/dc/file?name=Bbb90a1f813ad42419d5b96f01402593f637502647807249998_ShowErrorProject.zip&tid=bb90a1f813ad42419d5b96f01402593f637502647807249998)

```
BitmapImage NewBitmap = new BitmapImage();
NewBitmap.BeginInit();
NewBitmap.CacheOption = BitmapCacheOption.OnLoad;
NewBitmap.StreamSource = File.OpenRead(@".. \.. \img0010.jpg");
NewBitmap.Rotation = Rotation.Rotate90;
NewBitmap.DecodePixelWidth = 200;
NewBitmap.EndInit();
ImageControl.Source = NewBitmap;
```

I have attached the image file in the sample project.

---
### Original Comments

#### Feedback Bot on 3/1/2021, 11:06 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

#### Feedback Bot on 5/31/2021, 08:23 PM:

I detected that this issue hasn’t received a lot of activity, votes, or comments in the past 90 days. Based on this, the issues severity and affected area, it’s my experience that this issue is unlikely to get fixed. To improve the situation, consider following best practices for quality problem reports, and giving us more details on how this issue is impacting you.

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.