iOS: antialiasing text
iOS: antialiasing text
- Subject: iOS: antialiasing text
- From: Graham Cox <email@hidden>
- Date: Wed, 08 Jun 2011 09:56:56 +1000
I'm rendering text into a bitmap image context (in fact just a single letter, with a small drop-shadow). I am unable to get this text to be drawn anti-aliased, despite turning on all the shoulds and allows that pertain to this. Is anti-aliasing supported in a bitmap context on iOS? It seems to render text to the screen anti-aliased, what' s the difference? Or have I missed something? Here's the code:
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate( NULL,
PLAYER_IMAGE_SIZE,
PLAYER_IMAGE_SIZE,
8,
PLAYER_IMAGE_SIZE * 4,
colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault);
CGColorSpaceRelease( colourSpace );
UIGraphicsPushContext( context );
CGContextSetAllowsAntialiasing( context, true );
CGContextSetShouldAntialias( context, true );
CGContextSetInterpolationQuality( context, kCGInterpolationHigh );
UIColor* textColour = [colour shadowWithLevel:0.25]; // category methods on UIColor
UIColor* shadowColour = [colour highlightWithLevel:0.5];
CGContextSetAllowsFontSmoothing( context, true );
CGContextSetShouldSmoothFonts( context, true );
CGContextSetShadowWithColor( context, CGSizeMake( 3, flipped? 3 : -3 ), 4.0, [shadowColour CGColor]);
if( !flipped )
{
CGContextTranslateCTM( context, 0, PLAYER_IMAGE_SIZE );
CGContextScaleCTM( context, 1.0, -1.0 );
}
UIFont* font = [UIFont boldSystemFontOfSize:PLAYER_IMAGE_SIZE * 0.5];
CGSize box = [is sizeWithFont:font];
CGRect isBox;
isBox.size = box;
isBox.origin.x = ( PLAYER_IMAGE_SIZE * 0.5 ) - ( box.width * 0.5 );
isBox.origin.y = ( PLAYER_IMAGE_SIZE * 0.5 ) - ( box.height * 0.5 );
[textColour set];
[is drawInRect:isBox withFont:font lineBreakMode:UILineBreakModeClip];
CGImageRef image = CGBitmapContextCreateImage( context );
CGContextRelease( context );
UIGraphicsPopContext();
return image;
--Graham
_______________________________________________
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