绘制到新的“层".在C#中 [英] Drawing to a new "layer" in C#

查看:76
本文介绍了绘制到新的“层".在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建立一个小小的绘画程序,并试图结合图层的概念.

Building a little paint program and am trying to incorporate the concept of layers.

我正在使用PictureBox控件显示图像,并从PictureBox所显示的图像中获取Graphics对象并绘制到该对象.

I'm using a PictureBox control to display the image, and getting the Graphics object from the image being displayed by the PictureBox and drawing to that.

我的问题是我想弄清楚如何绘制到覆盖在图片框顶部的新Graphics对象,并能够在没有原始图像的情况下获得新绘制的图像.图像吸收到图形中.

My problem is I'm trying to figure out how to draw to a new Graphics object that is overlayed on top of the picture box, and be able to get the newly drawn image without the original image absorbed into the graphic.

如果我做类似的事情:

Graphics gr = Graphics.FromImage(myPictureBox.image);
gr.DrawRectangle(blah blah)

...我正在编辑图片框中的原始图像.我想要一种方法来仅捕获绘制为新图像的新内容,但仍将其显示为覆盖已存在的内容.

...I am editing the original image in the picture box. I want a way to only capture the new stuff being drawn as a separate image, but still have it displayed as an overlay over top of what was already there.

有人能指出我正确的方向吗?谢谢!

Anyone able to point me in the right direction? Thanks!

推荐答案

让它起作用了,也许我对最初的问题还不够清楚.

Got it working, perhaps I wasn't clear enough in my original question.

基本上,我最终要做的是将每个图层存储为一个单独的Image对象,然后仅挂接到控件的OnPaint方法并按顺序手动绘制图形,而不是仅绘制到PictureBox.Image.就像魅力一样!

Essentially what I ended up doing was storing each layer as a separate Image object, then just hooking into the OnPaint method of my control and manually drawing the graphics in order, instead of just drawing to PictureBox.Image. Works like a charm!

这篇关于绘制到新的“层".在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆