2010-09-03 78 views

回答

0

爲什麼你不只是有一個UIView,並把這兩個圖像作爲子視圖?

UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]]; 
UIView *imagesView = [[UIView alloc] initWithFrame:image.frame]; 
[imagesView addSubview:image]; 

UIImageView *imageToOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimagetooverlay.png"]]; 
[imageToOverlay setCenter:CGPointMake(10,10)]; 
[imagesView addSubview:imageToOverlay]; 

[self.view addSubview:imagesView]; 
+0

謝謝。 但是,這實際上是一個圖像的畫廊,將像20圖像..所以20 uiviews不能解決它。另外,我有點需要之後的縮略圖 – Zapacila 2010-09-03 21:33:42

4

Zapacila,你找到了你的問題的答案?你可以這樣做:

#define imageWidth 40 
#define imageHeight 60 

UIImage *image1 = [UIImage imageNamed:@"firstimage.png"]; 
UIImage *image2 = [UIImage imageNamed: @"secondimage.png"]; 

CGSize itemSize = CGSizeMake(imageWidth, imageHeight); 

UIGraphicsBeginImageContext(itemSize); 

CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); 
[image1 drawInRect:imageRect]; 
[image2 drawInRect:imageRect]; 

UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

UIImage overlappedImage是一個新的圖像,其中包含最初的,重疊的。說實話,我不知道這是否是達到這個結果的最好方法,但我知道它確實有效。

如果在此期間您找到了更有效的解決方案,請告訴我!