zoukankan      html  css  js  c++  java
  • iOS 图片压缩

    有时候从App上传图片给后台,由于图片较大, 需要将图片压缩一下。

    压缩的时候注意有的方案会卡线程,耗时。

    这里有个方案:不耗时,不卡线程

    -(UIImage *)makeThumbnailFromImage:(UIImage *)srcImage scale:(double)imageScale{
        
        UIImage *thumbail = nil;
        CGSize imageSize = CGSizeMake(srcImage.size.width*imageScale, srcImage.size.height*imageScale);
        
        if (srcImage.size.width != imageSize.width || srcImage.size.height != imageSize.height) {
            UIGraphicsBeginImageContext(imageSize);
            CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
            
            [srcImage drawInRect:imageRect];
            thumbail = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            
        }
        else{
            thumbail = srcImage;
        }
        return thumbail;
        
    }

    参考自:https://www.cnblogs.com/ChouDanDan/p/5038396.html#commentform

    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    单表查询
    解读python中SocketServer源码
    C++实训(2.3)
    C++实训(2.2)
    C++实训(2.1)
    C++实训(1.3)
    C++实训(1.1)
    顺序表的实现,在vs2019上运行成功
    p243_5(3)
    自考新教材-p176_5(2)
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/12325737.html
Copyright © 2011-2022 走看看