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

    ///原图压缩(压缩完直接nsdata类型保存到本地writeToFile)

    - (NSData *)resetSizeOfImageData:(UIImage *)source_image

    {

        NSData *data;

        if (UIImagePNGRepresentation(source_image) == nil) {

            data = UIImageJPEGRepresentation( source_image, 1);

        }else{

            data = UIImagePNGRepresentation(source_image);

            

        }

        //先调整分辨率

        CGFloat tempHeight;

        

        CGFloat tempWidth;

        UIImage *imghh = [UIImage imageWithData:data];

        CGSize newSize = CGSizeMake(imghh.size.width, imghh.size.height);

        if ( newSize.width<newSize.height){

            tempHeight = newSize.height / 1280;

            newSize = CGSizeMake(newSize.width/tempHeight, 1280);

        

        }else if (newSize.width>newSize.height){

            tempWidth = newSize.width / 1280;

            newSize = CGSizeMake(1280, newSize.height/tempWidth);

        }

        UIGraphicsBeginImageContext(newSize);

        [source_image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

        

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        

        UIGraphicsEndImageContext();

        

        //调整大小

        NSData *imageData;

        imageData = UIImageJPEGRepresentation(newImage, 0.3);

        return imageData;

    }

  • 相关阅读:
    get与post的区别
    shell脚本之变量替换
    Oracle sql性能优化
    HTTP协议报头
    Oracle查看表空间和删除表空间
    shell脚本之cat和wc命令
    java设计模式之单例模式
    Wireshark基本介绍和学习TCP三次握手转
    wrong number of arguments (1 for 2)
    PHP生成.url文件 网站常用的保存到桌面功能
  • 原文地址:https://www.cnblogs.com/liuting-1204/p/5606809.html
Copyright © 2011-2022 走看看