2

I'm trying to manually create a grid of images on the iPhone.

I've placed all my UIImageViews correctly, and they're all linked up correctly to the code. However, I have one small issue: my images are too big, and therefore, they need downscaling.

This shouldn't be much of a problem, as UIImageViews accept the "Aspect Fit" setting as a content mode; however, when an image is assigned to the image view, it is clearly slightly blurry and distorted.

Here is the original image, in full-size:

and here is the thumbnail image:

Now, it is quite obvious the second image is messed up in some ways, especially on the player's jersey number.

I imagine this has something to do with the resizing algorithm utilized by the SDK; should I be resizing images on my own before handing them over to UIImageView, or does the problem lie somewhere else ?

For the sake of completeness, here's the code I'm using, even though I'm certain this isn't where the problem originates from:

NSString *file = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:file];
image1.image = image;

EDIT: I'm not sure if this is important, but the original image is in the JPG format.

elliottbolzan
  • 1,057
  • 1
  • 15
  • 30
  • Not an answer, but you can more easily use images from your apps bundle by using `UIImage *image = [UIImage imageNamed:@"someBundledImage.png"];` – Mick MacCallum Aug 31 '12 at 16:23
  • Thank you, but I've simplified my code here for the sake of simplicity. In reality, the image is several folders deep within my bundle, and I find it easier to reference using the technique I've posted. – elliottbolzan Aug 31 '12 at 16:31

1 Answers1

4

Yes, resizing the image prior to the assignment to its ImageView will reduce the jaggies that you see. To resize a UIImage you can check this answer

Community
  • 1
  • 1
andreamazz
  • 4,256
  • 1
  • 20
  • 36
  • 1
    Thank you for your answer. I was looking for a good way to resize the image prior to displaying it, and your link did the trick. For those who want to maintain the "Aspect Fit" content mode, this link should provide with what you need: http://www.iphonedevsdk.com/forum/iphone-sdk-development-advanced-discussion/15001-aspect-fit-algorithm.html. – elliottbolzan Aug 31 '12 at 17:29