【问题标题】:Save processed image in iPhone library将处理后的图像保存在 iPhone 库中
【发布时间】:2012-09-10 13:51:32
【问题描述】:

我正在使用此代码翻转图像。

CGAffineTransform trans = CGAffineTransformScale(imageView.transform, -1, 1);
imageView.transform = trans;  

现在如果我想保存这个翻转的图像我应该怎么做?
我正在使用UIImageWriteToSavedPhotosAlbum(imageView.image, nil, nil, nil); 将图像保存在 iphone 库中,但它保存的是原始图像而不是翻转的图像。

欢迎大家提出建议。
感谢您的帮助。

【问题讨论】:

    标签: iphone xcode image-processing cgaffinetransform flip


    【解决方案1】:

    当你这样做时,你正在翻转 UIImageViewX-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);
    }
    

    【讨论】:

    • 感谢 Vakul 的回复。我以前试过这个。问题是,它第一次翻转图像,但如果我第二次点击按钮它什么也不做。我的意思是连续翻转在这里不起作用。有什么建议吗?
    • 您没有在问题的任何地方提到您想要进行翻转按钮操作.....您可以为此使用切换。
    【解决方案2】:

    使用此代码。首先,您将截取倒置图像的屏幕截图,将其保存到另一个 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);
    

    【讨论】:

    • 你是认真地建议他截取一张他已经拥有的图像吗?
    • 这就是投票的意义所在。你的回答不好,所以我投了反对票。如果你提供了一个好的答案,我会投赞成票。
    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多