2
的選擇部分我有一個的UIImage和CGPoint還告訴我,在什麼方向,我應該將它移動到創建另一個形象。背景可以是任何東西。
給出最初的UIImage如何創建新的UIImage?什麼是最有效的方法呢?
下面是我在做什麼:
int originalWidth = image.size.width;
int originalHeight = image.size.height;
float xDifference = [[coords objectAtIndex:0] floatValue];
float yDifference = [[coords objectAtIndex:1] floatValue];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 240, originalWidth, originalHeight)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeTopLeft;
CGRect imageFrame = imageView.frame;
imageFrame.origin.x = xDifference;
imageFrame.origin.y = -yDifference;
imageView.frame = imageFrame;
UIGraphicsBeginImageContext(tempView.bounds.size);
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
是否有更優化的版本?
我試過了,它沒有工作。這是幾個小時前的工作,所以我不清楚,但我不認爲這是填補形象。 – 2011-12-16 18:46:47