iOS 对图片进行压缩
来源:互联网 发布:网络本科教育 编辑:程序博客网 时间:2024/06/10 09:47
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
if ([info[UIImagePickerControllerOriginalImage]isKindOfClass:[UIImageclass]]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
//初始化imageNew为从相机中获得的--
UIImage *imageNew = image;
//设置image的尺寸
CGSize imagesize = imageNew.size;
if (image.size.width>image.size.height) {
imagesize.height = image.size.height/image.size.width*ImageMax;
imagesize.width =ImageMax;
} else {
imagesize.height =ImageMax;
imagesize.width = image.size.width/image.size.height*ImageMax;
}
//对图片大小进行压缩--
imageNew = [selfimageWithImage:imageNew scaledToSize:imagesize];
NSData *imageData =UIImageJPEGRepresentation(imageNew,1);
image = [UIImageimageWithData:imageData];
if (_delegate && [_delegaterespondsToSelector:@selector(getImageSuccessfulImage:camera:)]) {
[_delegategetImageSuccessfulImage:imagecamera:self->_isCamera];
}
}
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
//对图片尺寸进行压缩--
-(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;
}
- iOS 对图片进行压缩
- iOS 对图片进行压缩
- ios 对图片进行压缩
- iOS 对图片进行压缩处理
- 对图片进行压缩
- 对图片进行压缩
- 对图片进行压缩
- 对图片进行压缩
- iOS对图片压缩
- Android对图片进行压缩
- Android对图片进行压缩
- Android对图片进行压缩
- Android对图片进行压缩
- Android对图片进行压缩
- IOS获取图片进行压缩
- Linux上对图片进行压缩
- 对网站的图片进行压缩优化
- Linux上对图片进行压缩
- JavaScript中对象的创建及访问
- Java 中 this 用法小结
- MySQL innodb 索引 B+树实现 [复制链接]
- leetcode 144 Binary Tree Preorder Traversal C++
- Windows环境下Android Studio v1.0安装教程
- iOS 对图片进行压缩
- Lubuntu 16.04 LTS 安装 Qt/5.5/5.7/5.8
- 使用httpclient实现http接口调用实例
- WordCount程序结构
- Python2.7,32位下安装VDK
- 12张大数据图看看2016年世界各地发生大事件!
- jquery插入对象位置
- echarts 地图外边框投影 阴影立体效果
- C语言基础之文件、宏定义规则