Re: Transforming UIImage (rotate, translate, scale) and then crop to constant size
Re: Transforming UIImage (rotate, translate, scale) and then crop to constant size
- Subject: Re: Transforming UIImage (rotate, translate, scale) and then crop to constant size
- From: David Duncan <email@hidden>
- Date: Thu, 24 May 2012 09:49:07 -0700
On May 24, 2012, at 12:19 AM, Gustavo Adolfo Pizano wrote:
> For the transformation I'm using gesture recognizers.
> when I want to compose the image this is are the steps I'm doing
>
> UIGraphicsBeginImageContext(size) //size is a CGSize with 900x567
> CGContextRef ctx = UIGraphicsGetCurrentContext();
> CGContextSetAllowsAntialiasing(ctx, YES);
> CGContextSetShouldAntialias(ctx, YES);
> CGContextConcatCTM(ctx, _imageView.transform);
The image view's transform is going to be with respect to the center of the image view, but you are translating the context with respect to its origin. You need to translate to the center of the context before you apply this transform.
> [_imageView.image
> drawAtPoint:CGPointMake(-_image.size.width/2,-_image.size.height/2)];
>
> UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
> UIGraphicsEndImageContext();
As a general comment, you really shouldn't use your _imageView as a data model object (that is, as a container for the transform and image) as it unnecessarily locks you into using the UIImageView as the "truth". Consider for example if you wanted to use a placeholder image in your UI - you would need to somehow communicate the real image to this code via a UIImageView. Instead from an architecture POV you should should model this as an image and a transform, and the UIImageView and this code just happen to share these two components.
--
David Duncan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden