zoukankan      html  css  js  c++  java
  • ios中获编辑过的图片问题

    在开发中有时需要获取经过编辑过的图片,比图裁减,滤镜等,那么该如何获取呢?下面提出几种方法拱参考。

    1. 使用 AlAssetRepresentation的fullScreenImage方法,该方法最简单,获取的图片跟相册里面看到的图片一样,因为系统”相册”程序显示的图片是 fullScreenImage ,而不是fullResolutionImage ,但是该方法的问题是获得图片分辨率只有屏幕尺寸这么大,在碰到长图的时候就无能为力了,而如果我们使用fullResolutionImage 的话,会发现取的图片是原图,而非编辑过的。因此如果不考虑分辨率的问题,那么该方法是获取编辑过的图片的一个好的选择。  

    2.   使用图片metadata字典中的AdjustmentXMP信息,所有的asset会把他们相关的修改信息(裁减,滤镜等)放在metadata字典中的AdjustmentXMP中,因此我们可以解析出其修改信息,并应用到fullResolutionImage上, 这样就能获得高分辨率且编辑过的图片,即便是长图也能应付。

            ALAssetRepresentation *representation = [asset defaultRepresentation];
            CGImageRef fullResImage = [representation fullResolutionImage];
            NSString *adjustment = [[representation metadata] objectForKey:@"AdjustmentXMP"];
            if (adjustment) {
                NSData *xmpData = [adjustment dataUsingEncoding:NSUTF8StringEncoding];
                CIImage *image = [CIImage imageWithCGImage:fullResImage];
                
                NSError *error = nil;
                NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData
                                                             inputImageExtent:image.extent
                                                                        error:&error];
                CIContext *context = [CIContext contextWithOptions:nil];
                if (filterArray && !error) {
                    for (CIFilter *filter in filterArray) {
                        [filter setValue:image forKey:kCIInputImageKey];
                        image = [filter outputImage];
                    }
                    fullResImage = [context createCGImage:image fromRect:[image extent]];
                }
            }
            UIImage *adjustImage = [UIImage imageWithCGImage:fullResImage
                                                       scale:[representation scale]
                                                 orientation:(UIImageOrientation)[representation orientation]];
  • 相关阅读:
    caffe常用层: batchNorm层和scale层
    简述configure、pkg-config、pkg_config_path三者的关系
    python删除list中元素的三种方法
    Leetcode 872. Leaf-Similar Trees
    Leetcode 508. Most Frequent Subtree Sum
    Leetcode 572. Subtree of Another Tree
    Leetcode 894. All Possible Full Binary Trees
    Leetcode 814. Binary Tree Pruning
    Leetcode 557. Reverse Words in a String III
    python 多维list声明时的小问题
  • 原文地址:https://www.cnblogs.com/hello-LJ/p/3994859.html
Copyright © 2011-2022 走看看