0

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

4

2 回答 2

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;
}
于 2013-04-23T06:19:04.990 回答
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;
}
于 2013-04-23T06:21:02.593 回答