Prerna chavan
Prerna chavan

Reputation: 3249

CGContext draw image

I am drawing free hand lines on UIImageView using CGContext. But when i use

UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();

Image is drawn in Imageview using the size of imageView so the original image size is resized to the size of imageView. And again i have to resize the image size to its original size, while doing so it loses its quality. How to draw directly on image instead on imageView ? Also i must use the imageview to fit the image in the view so i can draw lines on it. Help please !!!

Upvotes: 0

Views: 8238

Answers (1)

stringCode
stringCode

Reputation: 2272

You could re-render image with lines on top of it

- (UIImage *)renderImage:(UIImage *)image atSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0.0, 0.0, size.width, size.height)];
    //Draw your lines here
    UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

Although depending on what you are doing with your app this might not be the best approach. Hope this helped.

Upvotes: 6

Related Questions