Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-05-2011, 09:13 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 2
monx_develop is on a distinguished road
Default Strange problem with transparent image rendering on iOS

I have UIImageView, which is used for showing image from resources. Image appears to be distorted. It is especially visible if you zoom the image in a graphics editor.
UIImageView size matches the size of the image.

currently used UIImageView parameters.
Code:
imgHeader.contentMode = UIViewContentModeCenter;
imgHeader.image = [UIImage imageNamed:@"logo.png"];
imgHeader.opaque = TRUE;
imgHeader.clearsContextBeforeDrawing = TRUE;
For UIImageView I tried changing parameters "opaque", "clearsContextBeforeDrawing" and "contentMode". Same result.


For resolving this issue I have also wrote classes AliasedLayer and AliasedImageView ( for antialiasing disabling the use of CGContextSetShouldAntialias and CGContextSetAllowsAntialiasing )
This is approximate code, there have been many attempts to change the code to correct image distortion. Same result.
Code:
@implementation AliasedLayer

-(id)init
{
	self = [super init];
	if (self) {
		img = [UIImage imageNamed:@"logo.png"];
	}
	return self;
}

-(void)drawInContext:(CGContextRef)context
{
	CGContextSetAllowsAntialiasing(context, false);
	CGContextSetShouldAntialias(context, false);
	CGContextDrawImage(context, CGRectMake(0., 0., 55., 18.), [img CGImage]);
}

- (void)renderInContext:(CGContextRef)ctx
{
	CGContextSetAllowsAntialiasing(ctx, false);
	CGContextSetShouldAntialias(ctx, false);
}

@end

@implementation AliasedImageView 


- (id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setClearsContextBeforeDrawing:YES];
	self.backgroundColor = [UIColor clearColor];
    }
    return self;
}


-(void)setImage:(UIImage *)img
{
	[image release];
	image = img;
	[image retain];
}

- (void)setNeedsDisplay{
    [self setNeedsDisplayInRect:self.frame];
}

-(void)dealloc
{
	[image release];
	[super dealloc];	
}

+(Class)layerClass
{
	return [AliasedLayer class]; 
}

- (void)drawRect:(CGRect)rect
{
	[super drawRect:rect];
	CGContextRef ctx = UIGraphicsGetCurrentContext();
	CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
	CGContextSetAllowsAntialiasing(ctx, false);
	CGContextSetShouldAntialias(ctx, false);
	CGContextDrawImage(ctx, rect, [image CGImage]);
}

-(void)awakeFromNib
{
	CGContextRef ctx = UIGraphicsGetCurrentContext();
	CGContextSetAllowsAntialiasing(ctx, false);
	CGContextSetShouldAntialias(ctx, false);
	[super awakeFromNib];
}

@end
There have been attempts to dynamically load the image as well as using xib file. Same result - logo image is distorted.
Any ideas on what is causing this and how to fix it?
Attached Images
File Type: png logo_comparison.png (2.7 KB, 5 views)
monx_develop is offline   Reply With Quote
Old 07-05-2011, 10:18 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

How do you position the image on your view ? Be sure that the CGRect used as the image view's frame does not have fraction values as its origins or bounds. You can use CGRectIntegral() function to make sure they are good.
nobre84 is offline   Reply With Quote
Reply

Bookmarks

Tags
uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 352
9 members and 343 guests
apatsufas, chemistry, lendo, leostc, Leslie80, lzwasyc, MarkC, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:33 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0