簡體   English   中英

Iphone 4和Iphone 5的圖像

[英]Image for Iphone 4 and Iphone 5

我的應用可以有很多background images 這個images我需要下載,所以我不想單獨下載iPhone 4iPhone 5 我使用方法self.view.backgroundcolor = [UIColor colorWithPatternImage:[UIImage imagenamed:@"myImage.jpg"]] 我想為iPhone 5下載一張image ,然后剪切頂部和底部邊框以便與iPhone 4一起使用。 我怎樣才能以最佳方式以編程方式完成。 哦,也許有解決我問題的最佳解決方案?

您可以使用此功能裁剪圖像定義您想要的矩形,因為剩下的圖像將被移除,因此您需要CoreGraphics.framework ,所以不要忘記添加到您的項目中。

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

嘗試這個

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