美文网首页
ios-->截图、生成指定大小图片以及压缩

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

作者: JakieZhang | 来源:发表于2017-10-16 16:52 被阅读24次

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

相关文章

网友评论

      本文标题:ios-->截图、生成指定大小图片以及压缩

      本文链接:https://www.haomeiwen.com/subject/nofluxtx.html