0
我有一個簡單的iPad圖像拼貼應用程序的問題。我有一個UIImageView,可以拖放不同的UIImageView。拖動的視圖可以旋轉和拉伸。當用戶完成對圖像的編輯後,我會將所有圖像合併到最終圖像上。我的解決方案已經使用UIGraphics並通過所有子視圖繪製大圖片,然後循環和借鑑他們的背景下:以上如何合併圖像並保持原始轉換
- (UIImage*)mergeImages
{
CGSize imageSize = imageView.frame.size;
UIGraphicsBeginImageContext(imageSize);
[imageView.image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
[[imageView subviews] enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) {
UIImage *imageOriginal = ((UIImageView*)object).image;
CGRect rect = ((UIImageView*)object).frame;
UIImage *imageToAdd = [self scaleImage:imageOriginal :rect.size];
// Find the w/h ratioes
float widthRatio = rect.size.width/imageOriginal.size.width;
float heightRatio = rect.size.height/imageOriginal.size.height;
// Calculate point to draw at
CGPoint pointToDrawAt;
if (widthRatio > heightRatio)
pointToDrawAt = CGPointMake(rect.origin.x + (rect.size.width/2) - (imageToAdd.size.width/2), rect.origin.y);
else
pointToDrawAt = CGPointMake(rect.origin.x, rect.origin.y + (rect.size.width/2) - (imageToAdd.size.height/2));
[imageToAdd drawAtPoint:pointToDrawAt];
}];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Save image in photogalery
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
return newImage;
}
工作的罰款,只要圖像不旋轉。所以我的問題是:
有沒有一種方法,我可以從子視圖中找到旋轉角度,還是我必須繼承UIView並使其成爲一個屬性?或者還有另外一種方法可以合併圖像並獲得圖形特定的屬性,如角度和過濾器?
如果我可以幫助進一步的代碼或任何只是評論。並提前感謝:)