码迷,mamicode.com
首页 > 其他好文 > 详细

NSData 与UIimage 关系 然后 压缩

时间:2014-11-26 13:35:48      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   sp   

1 //NSData转换为UIImage
2 NSData *imageData = [NSData dataWithContentsOfFile: imagePath];
3 UIImage *image = [UIImage imageWithData: imageData];
4
5 //UIImage转换为NSData
6 NSData *imageData = UIImagePNGRepresentation(aimae);

 

 

 

 

 1 //对图片尺寸进行压缩--
 2 -(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
 3 {
 4     // Create a graphics image context
 5     UIGraphicsBeginImageContext(newSize);
 6     
 7     // Tell the old image to draw in this new context, with the desired
 8     // new size
 9     [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
10     
11     // Get the new image from the context
12     UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
13     
14     // End the context
15     UIGraphicsEndImageContext();
16     
17     // Return the new image.
18    return newImage;
19 }

 

bubuko.com,布布扣

 

//按比例压缩
NSData  *imageData = UIImageJPEGRepresentation(self.uploadImage , 0.75);

 

NSData 与UIimage 关系 然后 压缩

标签:des   style   blog   http   io   ar   color   os   sp   

原文地址:http://www.cnblogs.com/zhibin/p/4122874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!