ios-->截图、生成指定大小图片以及压缩

1、截图

UIImage*snapshot;

CGImageRefcgScreen=UIGetScreenImage();

if(cgScreen){

snapshot=[UIImageimageWithCGImage:cgScreen];

CGImageRelease(cgScreen);

}

CGRectrect=CGRectMake(0,125,640,750);//创建要剪切的矩形框这里你可以自己修改

UIImage*res=[UIImageimageWithCGImage:CGImageCreateWithImageInRect([snapshotCGImage],rect)]

//res就是截图后的UIImage

2、生成指定大小图片

+ (UIImage *)compressImage:(UIImage *)imgSrc

{

CGSize size = {320, 480};

UIGraphicsBeginImageContext(size);

CGRect rect = {{0,0}, size};

[imgSrc drawInRect:rect];

UIImage *compressedImg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return compressedImg;

}

3、压缩

UIImage *img = [CImageUtil compressImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];

NSData *imageData = [[NSData alloc] initWithData:UIImageJPEGRepresentation(img, 0.1)];



来源:http://blog.csdn.net/mad2man/article/details/17171085

推荐阅读更多精彩内容