IOS 改变图片的大小

原创
2014/05/08 11:34
阅读数 1.3W

一、改变size

- (UIImage *)image:(UIImage*)image byScalingToSize:(CGSize)targetSize {
    UIImage *sourceImage = image;
    UIImage *newImage = nil;

    UIGraphicsBeginImageContext(targetSize);

    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = CGPointZero;
    thumbnailRect.size.width  = targetSize.width;
    thumbnailRect.size.height = targetSize.height;

    [sourceImage drawInRect:thumbnailRect];

    newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage ;
}



二、改变字节(多用于上传至服务器时)

UIKIT_EXTERN NSData *UIImagePNGRepresentation(UIImage *image);                               
UIKIT_EXTERN NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);







展开阅读全文
加载中
点击加入讨论🔥(1) 发布并加入讨论🔥
1 评论
3 收藏
0
分享
返回顶部
顶部