Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 2992 [details]
Source code that demonstrates the problem.
I have two images in my app, blue_button.png and firstname.lastname@example.org, and I use the following code to create the background image for a button:
UIImage image = UIImage.FromBundle("button_blue");
image = image.CreateResizableImage(new UIEdgeInsets(10, 10, 10, 10));
image = image.Scale(new SizeF(100, image.Size.Height));
On a retina display device, this code creates a button that uses blue_button.png instead of email@example.com. On the other hand, if I replace the call to UIImage.Scale with the following code, it uses firstname.lastname@example.org:
image = ScaleImage(image, new SizeF(100, image.Size.Height));
private UIImage ScaleImage(UIImage image, SizeF size)
UIGraphics.BeginImageContextWithOptions(size, false, 0);
image.Draw(new RectangleF(PointF.Empty, size));
image = UIGraphics.GetImageFromCurrentImageContext();
I suspect that the Scale method is using BeginImageContext instead of BeginImageContextWithOptions.
I've attached the program I used to figure this out. It creates two buttons using the two scaling methods described above. The easiest way to see the difference is to zoom in on a screenshot of the running program.
Thank you for tracking it down and providing a solution. This has now been fixed.
The next release with this fix will likely be 6.0.8.
The fix had to be reverted, because it broke existing code (see bug #11069).
I've added a new Scale overload, which does what you want:
UIImage.Scale (SizeF size, float scaleFactor);
this mimics BeginImageContextWithOptions' scale factor, where you can use the scale factor of the device if you pass in 0. In other words your code will look like this once fixed:
image = image.Scale(new SizeF(100, image.Size.Height), 0);