当前位置:编程学习 > C/C++ >>

UIImage 压缩

1.改变图片大小
[cpp]  
-(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;  
}  
 
 
 
2.改变图片质量
NSData *imageData = UIImageJPEGRepresentation(imageNew, 0.0001);
 
 
 
code
 UIImage *imageNew;
    imageNew = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imageNew = [self imageWithImage:imageNew scaledToSize:CGSizeMake(100, 100)];
    NSData *imageData = UIImageJPEGRepresentation(imageNew, 0.0001);
    
    m_selectImage = [UIImage imageWithData:imageData];
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,