0

我试图让用户将预先选择的图像拖放到他们从图书馆或照片库中选择的图像上,并将新编辑的图像作为一个整体保存。

下面的代码合并了两个图像,但没有将第二个图像保存在用户选择的同一位置。“userImage”是非静态的。再次感谢您的任何意见!

//Saves the image to the camera roll
- (IBAction)savePhoto:(id)sender {


UIImage *backgroundImage = [imageView image]; //This image is static

//This image will be moved around by a touchesMoved event
UIImage *userImage = [UIImage imageNamed:@"chopper_stash.png"];

UIGraphicsBeginImageContext(backgroundImage.size);
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];

//I realize that this sends the image to the top left, but how do I declare it's new location
[userImage drawInRect:CGRectMake(0,0, userImage.size.width, userImage.size.height)];

UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Save it to the camera roll
UIImageWriteToSavedPhotosAlbum(result, nil, nil, nil);
}
4

1 回答 1

0

你是说:

[userImage drawInRect:CGRectMake(0,0, userImage.size.width, userImage.size.height)];

好吧,显然这意味着将userImage在点绘制0,0,也就是左上角。如果您不想在此处绘制图像,请不要在此处绘制!把它画在你想要的地方。

顺便说一句,如果您以自己的大小绘制整个图像,则不需要使用drawInRect:; 只需使用drawAtPoint:. 它更简单。

于 2013-03-29T12:54:01.090 回答