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;

    }

  • 相关阅读:
    【学习笔记】查看CUDA版本
    如果Visual Studio太大,不妨还是用VSCode开发C#项目吧
    Visual Studio npm配置淘宝镜像
    c++读写锁--读者写者问题
    c++内存对象模型--vs2017下的分析,32位
    android作业
    android连接数据库
    android第十周(增删改查)
    android-购物车
    android计算器
  • 原文地址:https://www.cnblogs.com/liuting-1204/p/5606809.html
Copyright © 2011-2022 走看看