1 iOS裁剪图片
- (UIImage *)croppedImage:(UIImage *)image
{
if (image)
{
float min = MIN(image.size.width,image.size.height);
CGRect rectMAX = CGRectMake((image.size.width-min)/2, (image.size.height-min)/2, min, min);
CGImageRef subImageRef = CGImageCreateWithImageInRect(image.CGImage, rectMAX);
UIGraphicsBeginImageContext(rectMAX.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0, 0, min, min), subImageRef);
UIImage *viewImage = [UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
CGImageRelease(subImageRef);
return viewImage;
}
return nil;
}
2 iOS绘制背景色
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *bgColor = [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1.0];
CGContextSetStrokeColorWithColor(context, bgColor.CGColor);
CGContextSetFillColorWithColor(context, bgColor.CGColor);
CGRect bgRect = CGRectMake(0, kUserAlbumWidth, self.frame.size.width, kThumbWidth);
CGContextAddRect(context, bgRect);
CGContextDrawPath(context, kCGPathFillStroke);
转载来自:http://www.linuxidc.com/Linux/2013-03/80206.htm