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]];
  • 相关阅读:
    SQL索引一步到位
    Timeout expired超时时间已到. 达到了最大池大小 错误及Max Pool Size设置
    电脑开机的相关设置
    SELECT时为何要加WITH(NOLOCK)
    Sqlserver2008R2 数据库镜像配置步骤
    读写分离提高 SQL Server 并发性能
    八、数据结构
    七、数据库技术基础(二)
    缓存
    七、数据库技术基础(一)
  • 原文地址:https://www.cnblogs.com/hello-LJ/p/3994859.html
Copyright © 2011-2022 走看看