zoukankan      html  css  js  c++  java
  • SSave ALAsset image to disk fast on iOS

    I am using ALAsset to retrieve images like that:

    [[asset defaultRepresentation] fullResolutionImage]]

    This return CGImageRef which I want to save to disk as fast as possible...

    Solution 1:

    UIImage*currentImage =[UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
    NSData*currentImageData =UIImagePNGRepresentation(currentImage);
    [currentImageData writeToFile:filePath atomically:YES];

    Solution 2:

    CFURLRef url =(__bridge CFURLRef)[NSURL fileURLWithPath:filePath];
    CGImageDestinationRef destination =CGImageDestinationCreateWithURL(url, kUTTypePNG,1, NULL);
    CGImageDestinationAddImage(destination,[[asset defaultRepresentation] fullResolutionImage],nil);
    CGImageDestinationFinalize(destination);

    The problem is that both methods are very slow performing on a device. I takes about 2 seconds per image to perform this. And this is absolutely to long.

    Question: How can I speed up this image saving process? Or perhaps is there a better solution for this?

    UPDATE: The best performance improvements in both solutions is to save images to JPEG format instead of PNG. So for solution 1 have replaced UIImagePNGRepresentation with UIImageJPEGRepresentation. For solution 2 have replaced kUTTypePNG with kUTTypeJPEG.

    Also worth noting that second solution is way more memory efficient that first one.

  • 相关阅读:
    linux 网络编程比较好的文章
    linux 命令
    感冒了
    aa
    111
    仿京东(我的商城)鼠标上去弹出层效果
    仿汽车之家搜索页价格签区间(鼠标拖拽同时tip提示)
    关于DW 打不开后缀名为.ftl的文件 配置方法
    客户端与服务器段的交互 通过json
    jquery 阻止事件冒泡
  • 原文地址:https://www.cnblogs.com/lingzhao/p/3658398.html
Copyright © 2011-2022 走看看