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;

    }

  • 相关阅读:
    sqlserver中死锁问题
    sqlserver循环
    自动装箱和拆箱的原理
    资源文件
    SqlServer函数
    PGSql
    SOAP和REST
    Replication
    office等资料下载
    mysql
  • 原文地址:https://www.cnblogs.com/liuting-1204/p/5606809.html
Copyright © 2011-2022 走看看