• 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: Working with CGImage and Retina Display
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Working with CGImage and Retina Display


  • Subject: Re: Working with CGImage and Retina Display
  • From: Gustavo Pizano <email@hidden>
  • Date: Wed, 15 Dec 2010 21:38:03 +0100

Steve hello thanks for the reply..

it happens that I did a dirty work around here.

at application launch I load  the CGImageRef map depending on the device scale factor, so if it is 2.0 i load a @2x map otherwise the SD map. then when initializing the view which contains the and draw a portion of the map, I divide the frame's with and height by the device scale factor, and then in the draw method I  translate the context by the CGImageGetHeight(bc_itemImage)/scaleFactor , which at the end will will the view's bound's height, but to be sure I always take the CGImageRef height which never gets modified after doing transformation to the view.

Te results

a nice a sharp image is drawn in retina display, and its SD counterpart in the normal device without scale factor.

I dunno if it was the best approach but it works.

Im trying to avoid using UIImage, because i needed to load a CGImageRef form the map then convert to UIImage,  so I wanted to skip one step here, + I dunno what benefits I gain/lose by using CGImageRef instead of the UIImage facade.


Thanks for the reply once again

Gustavo



On Dec 15, 2010, at 9:10 PM, Steve Christensen wrote:

> I believe the issue is that CGImage just refers to an image with an effective scale factor of 1.0, no matter the device scale. It sounds like you need to somehow keep track of the image scale you're using so that you're always drawing at the correct size. One way would be to use +[UIImage imageNamed:], which will automatically load the correct version of your map image. When you draw that image, it does so with the scale in mind.
>
>
> On Dec 13, 2010, at 3:09 PM, Gustavo Pizano wrote:
>
>> Hello all.
>>
>> Im creating some views which draws a CGImage that is obtained from a Atlas Map, (Big map containing all the images).
>>
>> for iPHone 4 I have this map 2 times bigger than the normal one, so if I have a 2.0 scale on screen I load that one.
>>
>> What Im getting is that on iPhone 4 Im seeing all the views are drawing the CGImage too big, like 2 times more. So i think this has something to do with the 2.0 scale factor.
>>
>> what should I do in order to draw the CGImage properly sized?
>>
>> this is my drawing method which is working on iPad...
>>
>> 	CGContextRef context = UIGraphicsGetCurrentContext();
>>
>> 	CGContextSaveGState(context);
>> 	CGContextTranslateCTM(context, 0, CGImageGetHeight(bc_itemImage));
>> 	CGContextScaleCTM(context, 1.0, -1.0);
>> 	CGContextDrawImage(context, self.bounds, bc_itemImage);
>> 	CGContextRestoreGState(context);
>>
>> and this is my init method
>>
>> -(id)initWithImageFrame:(CGRect)imgFrame fromSheet:(CGImageRef)sheet{
>>
>> 	self = [super initWithFrame:CGRectMake(0, 0, imgFrame.size.width, imgFrame.size.height)];
>> 	if(self){
>> 		bc_itemImage = CGImageCreateWithImageInRect(sheet,imgFrame);
>> 		self.backgroundColor = [UIColor clearColor];
>> 		bc_isInBox = YES;
>> 	}
>>
>> 	return self;
>> }
>>
>> Thanks in advance for any help provided.
>>
>> Gustavo
>

_______________________________________________

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

References: 
 >Working with CGImage and Retina Display (From: Gustavo Pizano <email@hidden>)
 >Re: Working with CGImage and Retina Display (From: Steve Christensen <email@hidden>)

  • Prev by Date: Re: cannot access __block variable of array type inside block
  • Next by Date: Re: NSToolbar autovalidate [Misunderstanding]
  • Previous by thread: Re: Working with CGImage and Retina Display
  • Next by thread: Best practice for receiving data
  • Index(es):
    • Date
    • Thread