Bug 12247 - UIImage Scale() problem
Summary: UIImage Scale() problem
Status: RESOLVED DUPLICATE of bug 11069
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: 6.4 (async)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-05-15 06:13 UTC by banter+bugs
Modified: 2013-07-23 04:51 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED DUPLICATE of bug 11069

Description banter+bugs 2013-05-15 06:13:58 UTC
When you scale a UIImage using the Scale method, it appears to work, but creates a flawed CGImage when on a device.

To reproduce:

var zimg = UIImage.FromFile("Images/check.png");
zimg = zimg.Scale(new SizeF(20,20));
			
string fname = Session.Instance.newGameImagesDirectory + "check.png";
NSError err;
Console.WriteLine("size after scaling: {0}", zimg.Size);
// Image size is now 20x20

var data = zimg.AsPNG();

data.Save(fname, NSDataWritingOptions.Atomic, out err);
data.Dispose();
var sendingImage = UIImage.FromFile(fname);
Console.WriteLine("size after loading from bytes: {0}", sendingImage.Size);
//Image size is incorrectly loaded as 40x40 while debugging on the device, but correctly 20x20 on the simulator
//The byte lengths also differ between the simulator and the device.

// I was able to get a proper image saving on the device and loading the appropriate dimensions using the following alternative scale method:
public static UIImage zScale (this UIImage source, SizeF newSize)
		{
			UIGraphics.BeginImageContext (newSize);
			var context = UIGraphics.GetCurrentContext ();
			context.TranslateCTM (0, newSize.Height);
			context.ScaleCTM (1f, -1f);
			
			context.DrawImage (new RectangleF (0, 0, newSize.Width, newSize.Height), source.CGImage);
			
			var scaledImage = UIGraphics.GetImageFromCurrentImageContext();
			UIGraphics.EndImageContext();
			
			return scaledImage;         
		}

// I believe the Scale method has a bug in it, at least on devices.
Comment 1 Sebastien Pouliot 2013-05-15 08:46:34 UTC
Is it possible your simulator is non-retina and your devices are retina ?

If so can you try with a retina simulator and/or non-retina device ?

A similar issue was fixed recently (bug #11069) and will be part of the upcoming 6.2.6 release. 

The latest 6.3.5 (beta) release should already have the fix (if you want to confirm it's the same issue).
Comment 3 PJ 2013-07-09 05:11:55 UTC
Any chance you can still reproduce? 6.2.6 has been out for a while. Marking this bug as RESOLVED, NO RESPONSE for now. Please feel free to re-open if you still have an issue.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2013-07-23 04:51:58 UTC

*** This bug has been marked as a duplicate of bug 11069 ***