1

I have used the following code to crop an image so that it should fit into some fixed size (ex: 100*100)

  if(newSize.width == Thumbnail_Size) // Thumbnail_Size 100.0
  {               
      CGFloat side = width;
      if(width > height)
      {
        side = height;
      }
      CGRect croppedRect = CGRectMake(0, 0, side, side);
      CGImageRef croppedImage = CGImageCreateWithImageInRect(image.CGImage, croppedRect);
      newImage = [[UIImage alloc] initWithCGImage:croppedImage];
      if(newImage == nil) NSLog(@"could not scale image");
      return newImage ;       
  }

but the quality of the image is not good. Images are appearing as in the below screenshot:

enter image description here

I have set the imageview's contentmode as UIViewContentModeScaleAspectFit

[imageView setContentMode:UIViewContentModeScaleAspectFit];

What else I need to do to maintain the quality of the cropped image?

Dee
  • 1,887
  • 19
  • 47
  • I think you ment scaling not cropping. and when scaling you will lose some clarity. I think scaling with aspect ratio would have done the trick. would you give an idea on what were the original size? – Prajwal Udupa Jan 23 '13 at 07:18
  • hi try this http://stackoverflow.com/questions/3150364/how-use-cgimagecreatewithimageinrect-for-iphone-4-hd – Arun Jan 23 '13 at 12:55
  • I have even tried that. instead of imageWithCGImage method, I have used imageWithCGImage: scale: orientation: but the quality is still the same. – Dee Jan 24 '13 at 05:22

0 Answers0