• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions


  • Subject: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • From: Andreas Mayer <email@hidden>
  • Date: Tue, 27 Mar 2012 16:50:47 +0200

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 (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
      • From: Ray <email@hidden>
References: 
 >Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions (From: Ray <email@hidden>)
 >Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions (From: Marco Tabini <email@hidden>)

  • Prev by Date: Re: File types...
  • Next by Date: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Previous by thread: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Next by thread: Re: Question about UIImage, scaling, and UIGraphicsBeginImageContextWithOptions
  • Index(es):
    • Date
    • Thread