图片裁剪 旋转 转换
2015-07-01 本文已影响160人
mayday2024
//裁剪
-(UIImage *)getImageFromImage{
//大图bigImage
//定义myImageRect,截图的区域
CGFloat imgW = self.cutimg.size.width;
CGFloat imgH = self.cutimg.size.height;
CGRect myImageRect = CGRectMake(0.180 * imgH, 0.09375 * imgW,0.621 *imgH,0.8437 * imgW);
UIImage* bigImage= self.cutimg;
CGImageRef imageRef = bigImage.CGImage;
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
CGSize size;
size.width = 57.0;
size.height = 57.0;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, myImageRect, subImageRef);
UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
return smallImage;
}
//裁剪图片
UIImage *img = [self getImageFromImage];
CGImageRef cgimage=img.CGImage;
//旋转图片
UIImage *IMG = [UIImage imageWithCGImage:cgimage scale:1 orientation:UIImageOrientationRight];
//保存到相册
UIImageWriteToSavedPhotosAlbum(IMG, self, nil, nil);