zoukankan      html  css  js  c++  java
  • iOS 图片剪切和压缩的几个方法

    // 图片剪切

    - (UIImage*)clipImageWithImage:(UIImage*)image inRect:(CGRect)rect {
        CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, rect);

        UIGraphicsBeginImageContext(image.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextDrawImage(context, rect, imageRef);
        UIImage* clipImage = [UIImage imageWithCGImage:imageRef];
    //    CGImageCreateWithImageInRect(CGImageRef  _Nullable image, <#CGRect rect#>)
    //    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();      // 不同的方式
        UIGraphicsEndImageContext();
        
    //    NSData* data = [NSData dataWithData:UIImagePNGRepresentation(clipImage)];
    //    BOOL flag = [data writeToFile:@"/Users/gua/Desktop/Image/后.png" atomically:YES];
    //    GGLogDebug(@"========压缩后=======%@",clipImage);
        
        return clipImage;
    }

    // 图片压缩
    - (UIImage*)imageCompressImage:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth {
        CGSize imageSize = sourceImage.size;
        CGFloat width = imageSize.width;
        CGFloat height = imageSize.height;
        CGFloat targetWidth = defineWidth;
        CGFloat targetHeight = (targetWidth / width) * height;
        UIGraphicsBeginImageContext(CGSizeMake(targetWidth, targetHeight));
        [sourceImage drawInRect:CGRectMake(0,0,targetWidth, targetHeight)];
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        return newImage;
    }

  • 相关阅读:
    求字符串中最大的递增子序列
    分析函数改写自关联
    收集统计信息让SQL走正确的执行计划
    利用case when 减少表扫描次数
    利用查询提示优化SQL
    利用SQL进行推理
    查找字段连续相同的最大值
    优化有标量子查询的SQL
    将部分相同的多行记录转成一行多列
    .net 测试工具类
  • 原文地址:https://www.cnblogs.com/wfwenchao/p/5383215.html
Copyright © 2011-2022 走看看