我对从iPhone相机返回的图像有不同的需求。 我的应用程序将图像缩小以便上传和显示,最近,我添加了将图像保存到“照片”应用程序的功能。
起初,我将返回值分配给了两个变量,但结果发现它们正在共享同一个对象,因此我得到了两张缩小的图像,而不是一张完整比例的图像。
在弄清楚无法执行` UIImage *copyImage = [myImage copy]; `后,我通过下面的方式使用` imageWithCGImage `进行了复制。不幸的是,这并不奏效,因为复制品(此处为` croppedImage `)最终会与原始图像旋转90度。
有没有一种方法可以在不修改UIImagePickerControllerOriginalImage图像的情况下复制它?
起初,我将返回值分配给了两个变量,但结果发现它们正在共享同一个对象,因此我得到了两张缩小的图像,而不是一张完整比例的图像。
在弄清楚无法执行` UIImage *copyImage = [myImage copy]; `后,我通过下面的方式使用` imageWithCGImage `进行了复制。不幸的是,这并不奏效,因为复制品(此处为` croppedImage `)最终会与原始图像旋转90度。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Resize, crop, and correct orientation issues
self.originalImage = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
UIImageWriteToSavedPhotosAlbum(originalImage, nil, nil, nil);
UIImage *smallImage = [UIImage imageWithCGImage:[originalImage CGImage]]; // UIImage doesn't conform to NSCopy
// This method is from a category on UIImage based on this discussion:
// http://discussions.apple.com/message.jspa?messageID=7276709
// It doesn't rotate smallImage, though: while imageWithCGImage returns
// a rotated CGImage, the UIImageOrientation remains at UIImageOrientationUp!
UIImage *fixedImage = [smallImage scaleAndRotateImageFromImagePickerWithLongestSide:480];
...
}
有没有一种方法可以在不修改UIImagePickerControllerOriginalImage图像的情况下复制它?