我在iOS着色的图像绘制效率。我正在使用滑块来选择颜色。的iOS - (对滑块变化更新)
当我有设定为连续滑块“更新活动”,被调用该函数获取调用了很多(滑块从0到1535)等用户界面不是很敏感。
有没有一种办法可以让下面的代码更有效率?我知道我开始我每次调用函数时新的绘画语境 - 我可以“拯救”这种情况下,重新使用它呢?
在此先感谢。
- (IBAction)bodyColourChanged:(UISlider *)sender {
// get the UIColor from self.colourArray
UIColor *color = [self.colourArray objectAtIndex:sender.value];
UIImage *myImage = [UIImage imageNamed:@"body.png"];
// Begin a new image context to draw the coloured image onto
UIGraphicsBeginImageContext(self.bodyView.image.size);
// Get a reference to the context we created
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the fill colour
//[[UIColor colorWithRed:color.CGColor green:green blue:blue alpha:1.0] setFill];
[color setFill];
// translate/flip the graphics context (for transforming from CG* coords to UI* coords
CGContextTranslateCTM(context, 0, self.bodyView.image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// set the blend mode and the original image
CGContextSetBlendMode(context, kCGBlendModeOverlay);
CGRect rect = CGRectMake(0, 0, self.bodyView.image.size.width, self.bodyView.image.size.height);
CGContextDrawImage(context, rect, myImage.CGImage);
// Set a mask that matches the shape of the image, then draw (colour burn) a coloured rectangle
CGContextClipToMask(context, rect, self.bodyView.image.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context, kCGPathFill);
// Generate a new UIImage from the graphics context we drew onto
UIImage *colouredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.bodyView.image = colouredImage;
}
编辑:我着色的图像是相当大的。这是1541 x 2000像素,因为我希望能够放大而不损失质量。也许这是问题。我会继续修补,看看我能找到什么。
您是否尝试过CA TiledLayer的? –
你说得对,图像尺寸是一个因素,你是正对着的图像尺寸的无极限,正如大卫指出,平铺它。你需要在改变颜色的同时具有缩放功能吗?你可以做一个小副本,预览上的颜色变化那么一旦用户完成申请换到较大的图像,也许在后台? – Cocoadelica