ios - 如何在 iOS 中在没有 UIImageView 的情况下在 View 上绘制/绘制 UIIMage
<p><p>我正在这个应用程序中开发绘画应用程序,我正在使用 ACEDrawing 工具来绘制 View 。但我必须剪下画作的特定部分并粘贴到 View 的任何位置。
我可以将 View 的绘画复制为图像。我的代码在这里。</p>
<p>在.h文件中</p>
<p>@property (strong,nonatomic)ACEDrawingView *DrawingViews;</p>
<p>@property (nonatomic, strong)UIScrollView *myScrollView;</p>
<p>在 .m 文件中</p>
<pre><code>//creating the Drawing view
_DrawingViews = [ initWithFrame:CGRectMake(myOrigin, 0, self.testView.frame.size.width, self.testView.frame.size.height)];
_DrawingViews.drawTool=ACEDrawingToolTypePen;
_DrawingViews.tag=i;
_DrawingViews.delegate=self;
;
</code></pre>
<p>Inside Copy 方法之后。</p>
<p>-(void)copy:(id)sender{</p>
<pre><code>ACEDrawingView *dragView = ;// Getting ACEDrawing View with tag
CGSize size = .size;//just for size
UIGraphicsBeginImageContext(size);
[ renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGContextRef context=UIGraphicsGetCurrentContext();
;
UIGraphicsEndImageContext();
</code></pre>
<p>}</p>
<p>但是,我只能使用 UIImageView 将其粘贴为图像。我不知道如何将其粘贴为绘画概述,然后只能删除或重绘。</p>
<p>-感谢邓肯先生先生和所有愿意回答的人。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>UIImage 有drawInRect 等多种绘图方法。您已经了解了如何创建图形上下文。您可以使用 <code>drawInRect</code> 将图像绘制到图形上下文中。</p>
<p>(请注意,您想使用较长形式的 begin image context ,它采用比例和选项。(我不在我的 Mac 上查找函数名称。)如果您传入 0 的比例,它会创建Retina 设备上的 Retina 上下文。使用您使用的代码,它会将 Retina 图像降级为非 Retina 分辨率。)</p></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 中在没有 UIImageView 的情况下在 View 上绘制/绘制 UIIMage,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37857640/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37857640/
</a>
</p>
页:
[1]