简体   繁体   English

Iphone 4和Iphone 5的图像

[英]Image for Iphone 4 and Iphone 5

My app can have many images for background . 我的应用可以有很多background images This images I need download, so I don't want download separately for iPhone 4 and iPhone 5 . 这个images我需要下载,所以我不想单独下载iPhone 4iPhone 5 I use method self.view.backgroundcolor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"myImage.jpg"]] . 我使用方法self.view.backgroundcolor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"myImage.jpg"]] I want download one image for iPhone 5 and then cut top and bottom borders for use with iPhone 4 . 我想为iPhone 5下载一张image ,然后剪切顶部和底部边框以便与iPhone 4一起使用。 How can I do it programmatically with the best way. 我怎样才能以最佳方式以编程方式完成。 Oh maybe there are the best solutions for my problem? 哦,也许有解决我问题的最佳解决方案?

You can crop image using this function define the rect you want as image remaining will be removed for this you need CoreGraphics.framework , so dont forget to add in your Project. 您可以使用此功能裁剪图像定义您想要的矩形,因为剩下的图像将被移除,因此您需要CoreGraphics.framework ,所以不要忘记添加到您的项目中。

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

try this 尝试这个

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM