user1881612
user1881612

Reputation:

Image is less Sharper

In my application I capture image from camera. At that time sharpness of my image is fantastic but with the following lines of code my image is moved to next view.

- (UIImage *) imageFromView:(UIView *)view {

    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return viewImage;
}

When I see the image in next view at that time it is less sharper than before.

I want to mention, on both screens height and width of image view is same.

then what should be the problem with sharpness of image?

Upvotes: 0

Views: 109

Answers (2)

Nookaraju
Nookaraju

Reputation: 1668

Use this Line

UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);

instead of
UIGraphicsBeginImageContext(view.bounds.size);

Upvotes: 2

Cocoanetics
Cocoanetics

Reputation: 8247

You need to offset the image by 0.5,0.5. Otherwise Quartz distributes each point amongst the 4 neighbors.

In Quartz 0.0 is the corner of a pixel, not its center.

CGContextTranslateCTM(context, 0.5, 0.5);

See: https://developer.apple.com/library/mac/ipad/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html

Upvotes: 0

Related Questions