zoukankan      html  css  js  c++  java
  • 图片截取0825

    #pragma mark gzz0706

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

    {

        //先调整分辨率

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

        

        CGFloat tempHeight = newSize.height / 1024;

        CGFloat tempWidth = newSize.width / 1024;

        

        if (tempWidth > 1.0 && tempWidth > tempHeight) {

            newSize = CGSizeMake(source_image.size.width / tempWidth, source_image.size.height / tempWidth);

        }

        else if (tempHeight > 1.0 && tempWidth < tempHeight){

            newSize = CGSizeMake(source_image.size.width / tempHeight, source_image.size.height / tempHeight);

        }

        

        UIGraphicsBeginImageContext(newSize);

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

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        

        //调整大小

        NSData *imageData = UIImageJPEGRepresentation(newImage,1.0);

        NSUInteger sizeOrigin = [imageData length];

        NSUInteger sizeOriginKB = sizeOrigin / 1024;

        if (sizeOriginKB > maxSize) {

            NSData *finallImageData = UIImageJPEGRepresentation(newImage,0.50);

            return finallImageData;

        }

        

        return imageData;

    }

  • 相关阅读:
    D语言中的Range与C#中IEnumreable的区别
    D语言中使用Curl读取网页
    在D语言中如何调用Windows中的COM控件
    D语言反射
    D语言基本类型判断 traits.d
    Struts2 XML验证器
    (十四)Struts2 验证框架
    (十三)Struts2 发送电子邮件
    (十二)Struts2 数据库访问
    (十一)Struts2 文件上传
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5809321.html
Copyright © 2011-2022 走看看