• IOS 关于上传图片裁剪以及压缩,确保高清


    // 绘制图片
    -(NSData *) imageCompressForSize:(UIImage *)sourceImage targetSize:(CGSize)size{
        UIImage *newImage = nil;
        CGSize imageSize = sourceImage.size;
        CGFloat width = imageSize.width;
        CGFloat height = imageSize.height;
        CGFloat targetWidth = size.width;
        CGFloat targetHeight = size.height;
        CGFloat scaleFactor = 0.0;
        CGFloat scaledWidth = targetWidth;
        CGFloat scaledHeight = targetHeight;
        CGPoint thumbnailPoint = CGPointMake(0.0, 0.0);
        if(CGSizeEqualToSize(imageSize, size) == NO){
            CGFloat widthFactor = targetWidth / width;
            CGFloat heightFactor = targetHeight / height;
            if(widthFactor > heightFactor){
                scaleFactor = widthFactor;
            }
            else{
                scaleFactor = heightFactor;
            }
            scaledWidth = width * scaleFactor;
            scaledHeight = height * scaleFactor;
            if(widthFactor > heightFactor){
                thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
            }else if(widthFactor < heightFactor){
                thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
            }
        }
        
        UIGraphicsBeginImageContext(size);
        CGRect thumbnailRect = CGRectZero;
        thumbnailRect.origin = thumbnailPoint;
        thumbnailRect.size.width = scaledWidth;
        thumbnailRect.size.height = scaledHeight;
        [sourceImage drawInRect:thumbnailRect];
        newImage = UIGraphicsGetImageFromCurrentImageContext();
        
        if(newImage == nil){
            NSLog(@"scale image fail");
        }
        
        UIGraphicsEndImageContext();
        NSLog(@"==---==%@",newImage);
        return UIImageJPEGRepresentation(newImage, 1);
        
    }

  • 相关阅读:
    【JavaScript】--ajax
    【Django】--Models 和ORM以及admin配置
    【Django】--基础知识
    【jQuery】--图片轮播
    双系统 windows引导项添加
    LVM
    linux安全加固
    oracle 11G 配置侦听文件
    LVM
    《virtual san 最佳实践》节选 Virtual SAN的发展与现状
  • 原文地址:https://www.cnblogs.com/yangxiaolong/p/5435012.html
Copyright © 2020-2023  润新知