1
我有兩個包含兩個不同圖像的imageView。我的firstImageview
有主圖像,然後我添加了一個更多的imageview作爲firstImageview
的子視圖,如[firstImageview addSubView:secondImageview]
。我需要這個在一個單一的形象。將兩幅圖像合併爲單幅圖像,然後頂部圖像在ios sdk中變大
我使用下面的代碼(它工作順利):
- (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage {
UIImage *image = nil;
CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height));
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} else {
// UIGraphicsBeginImageContext(newImageSize);
}
[firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2),
roundf((newImageSize.height-firstImage.size.height)/2))];
[secondImage drawAtPoint:CGPointMake(roundf((newImageSize.width-secondImage.size.width)/2),
roundf((newImageSize.height-secondImage.size.height)/2))];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
但在我resultedImage,topImage secondImageview.image
變大。
我的觀點看起來像(前合併):
我造成的圖像合併後(上面的圖像變大):
如何合併這些圖像,而不secondImageview
變大?