我正在使用此代码翻转图像。
CGAffineTransform trans = CGAffineTransformScale(imageView.transform, -1, 1);
imageView.transform = trans;
现在,如果我想保存这个翻转的图像,我该怎么办?
我正在使用UIImageWriteToSavedPhotosAlbum(imageView.image, nil, nil, nil);
将图像保存在iPhone库中,但它正在保存原始图像而不是翻转的图像。
欢迎您的建议。
谢谢你的帮助。
当你这样做时,你正在翻转UIImageView
它的X-Axis
而不是UIImage
。所以很明显,代码会保存你的原始图像。
翻转UIImage
而不是UIImageView
然后保存 -
UIImage *flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
现在使用您的保存方法 -
UIImageWriteToSavedPhotosAlbum(flippedImage, nil, nil, nil);
编辑:
-(void)tapFlipXPosition:(id)sender
{
UIImage* sourceImage = yourSourceImage;
UIImage* flippedImage;
if(sourceImage.imageOrientation == UIImageOrientationUpMirrored)
{
flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUp];
}
else
{
flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage scale:1.0 orientation: UIImageOrientationUpMirrored];
}
UIImageWriteToSavedPhotosAlbum(flippedImage, nil, nil, nil);
}
使用此代码。在这里,首先您将截取反转图像的屏幕截图,将其保存到另一个imageviewView中,然后将此特定的"新图像"保存到PhotoLibrary中。
UIGraphicsBeginImageContext(BaseView.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *attachimage = [[UIImage alloc]initWithData:Data];
UIImage *viImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
attachimage = viImage;
UIImageWriteToSavedPhotosAlbum(viImage, nil, nil, nil);