0

I'm working on a comic viewer app that downloads the latest content from a server. It downloads a single file regardless of the screen scale. What I'd like to do is make this file work correctly on both screens.

What's the procedure for this and how should I size the photos to fit? The trouble I'm having is that the graphics are retina screen size, but the iPhone doesn't interpret them as such. That means they're displayed twice as large as they should be.

MechEngineer
  • 1,399
  • 3
  • 16
  • 27

2 Answers2

0
CGImageRef cgImage = [myImage cgImage];
UIImage *retinaImage = [UIImage imageWithCGImage:cgImage scale:2.0 orientation:UIImageOrientationUp];

You could also change your image's dpi value in an image editor to make UIImage recognize the scale automatically.

Generally though, you should use lower-resolution images on devices that don't have a retina display because otherwise you're wasting precious memory.

omz
  • 53,243
  • 5
  • 129
  • 141
  • That makes sense, but I was talking more about adjusting on the fly depending on the device. In other words, you download a 100x100 image, and the resulting UIImage after scaling is 50x50 on iPhone 3G3 but 100x100 on iPhone 4. – MechEngineer Dec 21 '11 at 16:47
0

For normal screen, you can resize them programmatically, by adding a scale category to the UIImage class by example, there are many code samples on stackoverflow like :

UIImage resize (Scale proportion)

For retina, you need to set the scale of the UIImage to let the ios know for what screen size it is used (you can set this with the initWithCGImage:scale:orientation: method of UIImage).

Community
  • 1
  • 1
Johnmph
  • 3,391
  • 24
  • 32