2013-04-23 58 views
0

我的应用程序可以有许多imagesbackground。这images我需要下载,所以我不想单独下载iPhone 4iPhone 5。我使用方法self.view.backgroundcolor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"myImage.jpg"]]。我想下载一个imageiPhone 5,然后切割顶部和底部的边界,以便与iPhone 4一起使用。我怎样才能以最好的方式编程。哦,也许有我的问题最好的解决方案?Iphone 4和iPhone 5的图像

回答

1

您可以使用此功能裁剪图像定义您想要的矩形,因为剩余的图像将被删除 为此,您需要CoreGraphics.framework,所以不要忘记添加到您的项目中。

- (UIImage *)imageByCroppingtoRect:(CGRect)rect fromImage:(UIImage *)image 
{ 
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect); 
    UIImage *cropped = [UIImage imageWithCGImage:imageRef]; 
    CGImageRelease(imageRef); 
    return cropped; 
} 
1

试试这个

- (UIImage *)cropImage:(UIImage *)oldImage { 
    CGSize imageSize = oldImage.size; 
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageSize.width,imageSize.height - 100),NO,0.); // this height you want to change 
    [oldImage drawAtPoint:CGPointMake(0, -46) blendMode:kCGBlendModeCopy alpha:1.];// from top to change X is never change 
    UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return croppedImage; 
}