iphone缩小uIImage图片
UIImage的缩小
有时候,项目中,要用到上传图片,从图片库里取出的图片有的太大了,而要上传的时候,会很费时间,而且也没必要太大,所以就把图片综缩小一下,再传!
[cpp]
#pragma UIImagePickerDelagate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[self.imagePopoverController dismissPopoverAnimated:YES];
/*
选取成功后在界面上进行显示
*/
//压缩图片
int iWidth = image.size.width;
int iHeight = image.size.height;
if (iWidth>300) {//300你自定义大小,想要弄多大,就弄多大
iWidth = 300;
iHeight = image.size.height*iWidth/image.size.width;
if (iHeight>300) {
iHeight = 300;
iWidth = image.size.width*iHeight/image.size.height;
}
}
image = [self scaleToSize:image :CGSizeMake(iWidth, iHeight)];//主要在这里
NSData* imageData = UIImagePNGRepresentation(image);
[self saveImage:imageData WithName:@"pic.jpg"];//保存图片
}
#pragma UIImagePickerDelagate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[self.imagePopoverController dismissPopoverAnimated:YES];
/*
选取成功后在界面上进行显示
*/
//压缩图片
int iWidth = image.size.width;
int iHeight = image.size.height;
if (iWidth>300) {//300你自定义大小,想要弄多大,就弄多大
iWidth = 300;
iHeight = image.size.height*iWidth/image.size.width;
if (iHeight>300) {
iHeight = 300;
iWidth = image.size.width*iHeight/image.size.height;
}
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>