Trying to superimpose a smaller image which may be scaled or rotated onto a lager image:
+ (UIImage*)addToImage:(UIImage *)baseImage newImage:(UIImage*)newImage atPoint:(CGPoint)point transform:(CGAffineTransform)transform {
UIGraphicsBeginImageContext(baseImage.size);
[baseImage drawInRect:CGRectMake(0, 0, baseImage.size.width, baseImage.size.height)];
[newImage drawAtPoint:point];
//How would I apply the transform?
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
How would I apply the CGAffineTransform to newImage in this context?
With Interface Builder it's pretty easy to add and configure a UIImageView. The first step is to drag the UIImageView onto your view. Then open the UIImageView properties pane and select the image asset (assuming you have some images in your project).
An object that manages image data in your app.
You can use the CoreImage framework, this allows transformations on CIImage
instances. For example:
CGAffineTransform transform = ...;
CIImage* coreImage = newImage.CIImage;
if (!coreImage) {
coreImage = [CIImage imageWithCGImage:newImage.CGImage];
}
coreImage = [coreImage imageByApplyingTransform:transform];
newImage = [UIImage imageWithCIImage:coreImage];
You'll need to ensure that after calling .CIImage
, that is isn't nil
. This will occur if the UIImage
was initialised with a CGImage
. If this is the case, then you'll need to allocate a CIImage
yourself with the appropriate initialiser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With