user3121366 user3121366 - 4 months ago 40
iOS Question

iOS - UIImage Resize to Bigger get Blurry

I'm trying to resize the UIImage

Before the UIImage:
enter image description here

After this code and UIImage:

UIGraphicsBeginImageContext (CGPointMake(155,139));
[currentImageView.image drawInRect:CGRectMake(0,0,155,139)];
currentImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"get size : %@",NSStringFromCGSize(currentImageView.image.size));


NSLog: get size : {155,139}


Last, I try to restore the size by this code. but its blurry.

UIGraphicsBeginImageContext (OriginalSize);
[currentImageView.image drawInRect:CGRectMake(0,0,OriginalSize.width,OriginalSize.height)];
currentImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"get size : %@",NSStringFromCGSize(cnurrentImageView.image.size));


NSLog: get size : {1024,352}


What happened?
Have any suggestions and advice?

Answer

You are making two mistakes,

1.Reducing the image size and setting it to a larger size imageView, this can be fixed with the code,

    imageView.contentMode = UIViewContentModeScaleAspectFit;

2.You have resize the original image to a smaller size, then resizing the smaller image to original size, this will stretch the image.