Hi,guys
I apologize first ,because My English is no good. I will try my best to explain my problem.
I am building a photo app. You can choose images and move, rotate ,scale them. Finally, you can merge them to create a new image. I had no problem to display them on the screen, but when i wanted to merge them I encountered a problem.
Below is my code, i have not done scale yet, but i have done move and rotate. Rotation works correctly, but the location of the image is wrong.Who can help me, i will appreciate a lot!
enter code here
UIImage *newImage;
UIGraphicsBeginImageContext(CGSizeMake(320.0f,480.0f));
CGContextRef contextComponent = UIGraphicsGetCurrentContext();
for (UIImageView *subview in subviews) {
if (subview.tag >= kBottleImageView || subview.tag == kPhotoView || subview.tag == kPhotoFrameImageView) {
CGContextSaveGState(contextComponent);
CGContextTranslateCTM(contextComponent, subview.center.x, (subview.bounds.size.height - subview.center.y));
CGContextTranslateCTM(contextComponent, -subview.bounds.size.width/2, -subview.bounds.size.height/2);
if (subview.tag != kPhotoFrameImageView ) {
if (subview.totalAngle != 0) { //totalAngle is the total rotated angle of the view
CGContextTranslateCTM (contextComponent, subview.bounds.size.width/2, subview.bounds.size.height/2);
CGContextRotateCTM(contextComponent, (subview.totalAngle));
CGContextTranslateCTM (contextComponent, -subview.bounds.size.width/2, -subview.bounds.size.height/2);
}
}
[subview.image drawInRect:CGRectMake(0.0, 0.0, subview.bounds.size.width, subview.bounds.size.height)];
CGContextRestoreGState(contextComponent);
}
}
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();