【发布时间】:2012-07-03 11:36:58
【问题描述】:
在我的应用程序中,我用手指在图像视图上绘制了一个矩形。矩形是使用drawRect 方法创建的,并添加到该图像视图中。
现在我的问题是我必须将该图像与这些矩形一起存储在照片库中。就像在 imageview 上有矩形的图像。
谁能帮助我找到如何做到这一点?
这是我的drawRect 方法代码:
-(void)drawRect:(CGRect)rect
{
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 5.0);
CGContextSetRGBStrokeColor(contextRef, 255.0, 1.0, 0.0, 1.0);
CGContextSetStrokeColorWithColor(contextRef,[UIColor redColor].CGColor);
// Draw the border along the view edge.
CGContextStrokeRect(contextRef, rect);
}
【问题讨论】:
-
如何绘制矩形?你能在这里显示代码吗?
-
-(void)drawRect:(CGRect)rect { CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(contextRef, 5.0); CGContextSetRGBStrokeColor(contextRef, 255.0, 1.0, 0.0, 1.0); CGContextSetStrokeColorWithColor(contextRef,[UIColor redColor].CGColor); // 沿视图边缘绘制边框 CGContextStrokeRect(contextRef, rect); } }
-
以这种方式创建矩形并使用 addsubview 在 imageview 上添加此视图
-
@Naresh - 问题上有一个“编辑”按钮,可以让问题所有者编辑和更新问题。这有助于澄清,尤其是发布代码 - 因为这些小 cmets 中的代码很难阅读。干杯!
标签: ios ipad cgcontext photolibrary