Am 27.03.2012 um 13:47 schrieb Marco Tabini:

> When you save to a file format that supports metadata, like JPEG, some of the 
> metadata is stored there, while other is derived from the file name. So, for 
> example, if you were to save a PNG file to disk with an @2x suffix, upon 
> loading it with -imageNamed: UIImage would automatically know to set up the 
> resulting object as a 2x scale image.
> 
> When the filename convention is not available, that metadata needs to be 
> saved somewhere—in your case, you derive it from the file size, which, as you 
> mention, is not very portable.

The documentation for UIImage -scale says:

"If you load an image from a file whose name includes the @2x modifier, the 
scale is set to 2.0. If the filename does not include the modifier but is in 
the PNG or JPEG format and has an associated DPI value, a corresponding scale 
factor is computed and reflected in this property. "

So I would expect PNG images to retain their scale value when saved and loaded.

If this does not work, there seems to be a bug somewhere.
Ray, did you try to explicitly set the image's scale value before creating the 
PNG representation?

Something like this:

UIImage *newImage;
NSData *imageData;

UIGraphicsBeginImageContext(CGSizeMake(44.0, 44.0));
[selectedImage drawInRect:CGRectMake(0.0, 0.0, 44.0, 44.0)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
newImage.scale = 2.0;  // <---

imageData = UIImagePNGRepresentation(newImage);


Andreas
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to