【发布时间】:2013-11-10 13:25:18
【问题描述】:
我想在我的 UIIMage 上多画 1 条线,现在我这样做:
-(void)drawRect
{
UIGraphicsBeginImageContext(myImage.size);
code to draw line on current context...
draw previous info from myImage:
[myImage drawInRect:myRect];
//store info from context back to myImage
myImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//append the image on the right side of current context:
[myImage drawInRect:myRightRect];
}
问题是我认为每次绘制整个图像仅增加 1 行非常昂贵,有人知道如何优化它吗?
【问题讨论】:
-
信息太少,无法给您准确的答案...通常,drawRect 覆盖工作缓慢,这是“非常昂贵的”,是的。但是,在某些情况下,您可能会摆脱此类操作。如果您只需要在视图上显示一行 - 使用此行添加子视图。如果您需要一些更难的绘图 - 使用蒙版,alphas。如果您确实需要这是“带线条的图像”(例如,用于保存到文件或上传到服务器) - 是的,您需要像您一样在图像上画线。附:尽量让你的问题更具体,提供更多细节。
-
是屏幕显示还是不显示?是否应该在 drawRect 方法中完全添加该行?
-
为了更清楚,我编辑了我的问题。