- (UIImage *)handleImage:(UIImage *)originalImage
{
CGSize originalsize = [originalImage size];
CGImageRef imageRef = nil;
CGFloat tempWidth = originalsize.width*0.75;
CGFloat imageW = originalsize.width;
imageRef = CGImageCreateWithImageInRect([originalImage CGImage], CGRectMake(0, originalsize.height/2-tempWidth*0.5, imageW, tempWidth));//获取图片整体部分
UIGraphicsBeginImageContext(CGSizeMake(imageW, tempWidth));//指定要绘画图片的大小
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(con, 0.0, tempWidth);
CGContextScaleCTM(con, 1.0, -1.0);
CGContextDrawImage(con, CGRectMake(0, 0, imageW, tempWidth), imageRef);
UIImage *standardImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRelease(imageRef);
return standardImage;
}
使用:
UIImage *newImage = [self handleImage:image];