Kalle
Kalle

Reputation: 13346

Why are these UIImages so "blurry"?

In an app I'm working on, I've got a few UIImages which for some reason come out really blurry. This specifically applies to two icons I use which are fairly small (80x15 and 65x15).

Top is original, below is blurry

iPad Simulator

(Update: added iPad Simulator output as well -- it is blurry just as the iPad output)

Top left and right are original images, bottom left and right are how they come out on the iPad. I actually got complaints about these being awfully blurry from users, so it's not just me.

The code where one of these is put in place looks like this (can show code for other one at request):

UIButton *bWeb = [[UIButton alloc] initWithFrame:
    CGRectMake(attriboffset, height - 20.f, 65.f, 15.f)];

[bWeb addTarget:self action:@selector(clickWebLink:)
    forControlEvents:UIControlEventTouchUpInside];

bWeb.userInteractionEnabled = YES;

[bWeb setImage:[UIImage imageNamed:@"button-weblink-65x15.png"] 
    forState:UIControlStateNormal];
[bWeb setImage:[UIImage imageNamed:@"button-weblink-highlighted-65x15.png"] 
    forState:UIControlStateHighlighted];

[self addSubview:bWeb];
[bWeb release];

The original images are (in case you think it might be a formatting issue with the actual PNG files): cc-by.png, weblink.png

Upvotes: 0

Views: 941

Answers (4)

Jaanus
Jaanus

Reputation: 17866

What is attriboffset?

Like hoha says, if the numbers are not integers, you will end up with fractional offsets, and devices will do some blurry antialiasing to compensate for that. The numbers should not have fractions.

Upvotes: 2

Kirby Todd
Kirby Todd

Reputation: 11566

Open your images in preview and resave them.

Upvotes: 0

hoha
hoha

Reputation: 4428

Make sure that all numbers in UIButton's frame are rounded/truncated to integers.

Upvotes: 3

James Bedford
James Bedford

Reputation: 28982

I think that for some reason the image is being rendered with some kind of unnecessary processing that is causing the quality loss.

Try changing the contentMode property of your UIButton to UIViewContentModeCenter. The default is UIViewContentModeStretch.

Upvotes: 0

Related Questions