0

I have a problem when trying to display small (16x16) UIImages, they appear a bit blurry. These UIImages are favicons I download from different websites and I have compared them with some images from other apps and they're blurrier.

I'm displaying them on a custom UITableViewCell like below :

NSData *favicon = [NSData dataWithContentsOfURL:[NSURL URLWithString:[subscription faviconURL]]];

    if([favicon length] > 0){
        UIImage *img = [[UIImage alloc] initWithData:favicon];

        CGSize size;
        size.height = 16;
        size.width = 16;
        UIGraphicsBeginImageContext(size);
        [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        cell.mainPicture.image = scaledImage;
    }

Is there anything wrong with my custom UITableViewCell or the way I download the image ?

Thank you.

[EDIT 1] : By the way, .ico and .png look the same. [EDIT 2] : I'm working on an iPad 2, so no Retina display.

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121

1 Answers1

2

When you display the resultant UIImage to the user, are you aligning the view on pixel boundaries?

theImage.frame = CGRectIntegral(theImage.frame);

Most of your graphics and text will appear to be blurry if your views are positioned or sized with non-integral values. If you run your app in the simulator, you can turn on "Color Misaligned Images" to highlight elements with bad offsets.

kubi
  • 48,104
  • 19
  • 94
  • 118
  • I found the problem thanks to kubi's post and n8gray post in http://stackoverflow.com/questions/2034016/uiimageview-renders-image-differently-to-original My UIImageView was 35px wide and I was trying to center a 16px wide images which would have left 9.5px on echo side of the image... Thank you all – Titouan de Bailleul Jan 13 '12 at 20:35