iOS 压缩图片,判断图片格式
来源:互联网 发布:网络侦探dlc 编辑:程序博客网 时间:2024/05/29 14:43
最近在做上传图片处理,遇到了不少麻烦,比如用相机拍出来的图片太大,取得的图片方向有问题等。
图片方向的问题,请看
点击打开链接对图片进行压缩的话,网上看了些资料也就是:
1.改变图片的大小
2.改变图片的质量
1.改变图片大小的方法
可以搞一个 UIImage+XX 的分类
** //对图片尺寸进行压缩-- */+ (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize{ // Create a graphics image context UIGraphicsBeginImageContext(newSize); // Tell the old image to draw in this new context, with the desired // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage;}
进行压缩
// 压缩 CGFloat proportion = (CGFloat)(editedImage.size.width/editedImage.size.height); UIImage *image = [UIImage imageWithImage:editedImage scaledToSize:CGSizeMake(500, (CGFloat)500/proportion)];
proportion比例
editedImage原始图片
然调用方法
/** //对图片尺寸进行压缩-- */+(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
获得一张新图片
1.改变图片质量的方法
/** //压缩图片质量 */+(UIImage *)reduceImage:(UIImage *)image percent:(float)percent{ NSData *imageData = UIImageJPEGRepresentation(image, percent); UIImage *newImage = [UIImage imageWithData:imageData]; return newImage;}
percent
比例,比例的话,如果你要求图片小于1M,而图片大小比1M大,那么比例你可以用
1M / 图片的大小
即:ONEM/imageData.length
2.判断图片格式
if (UIImagePNGRepresentation(image) == nil) { image_fileType = @"JPEG";}else { image_fileType = @"PNG";}
1 0
- iOS 压缩图片,判断图片格式
- iOS 图片格式 图片压缩
- ios判断图片格式类型
- 图片质量压缩 与 图片格式 JPEG PNG
- 图片格式的选择+图片压缩---网页制作
- PB 判断图片格式属于那种图片
- 判断图片格式
- 图片格式判断
- 判断图片格式
- VB.NET 判断图片格式(检查图片是否非法)
- Struts2图片文件上传,判断图片格式和图片大小
- Struts2图片文件上传,判断图片格式和图片大小
- Struts2图片文件上传,判断图片格式和图片大小
- php判断文件上传图片格式是否为图片
- IOS 图片压缩
- ios--图片压缩/缩放
- IOS 图片压缩
- ios图片压缩
- 接口隔离原则
- 山东汶上:黄栌俏销带动红栌发展
- MFC对话框中的单选按钮(Radio)
- 迪米特法则
- Android屏幕适配全攻略(最权威的官方适配指导)
- iOS 压缩图片,判断图片格式
- MyEclipse2013自动生成Hibernate4.1
- iOS 跳转按钮设置2种
- Mini-XML库在VC6.0及其他VS环境下的使用
- 你应该做到会读代码
- Android HTTP通信
- 百度地图兴趣点检索
- static关键字在C++中的作用
- 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。