最快的方式在窗体窗体上绘制图像的叠加层 [英] Fastest way to draw an overlay on an image in windows forms

查看:212
本文介绍了最快的方式在窗体窗体上绘制图像的叠加层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.net中绘制图像的最快方法是什么?



我试图在另一幅图像上绘制图像,窗体控制。我知道,当我尝试直接使用循环绘制它时,它需要一个Eon。



我听到的选项有GDI +,Direct Draw或DX10。我从一个固定大小的位图开始,在将它分配给一个表单对象之前,对它应用了3个以上的重叠图层。



谢谢,

解决方案

如果您的叠加层是图像(也许是带有透明度的PNG图像),那么一般技术是从图像中创建一个Graphics对象,我想绘制,然后将其他图像渲染到它上面:

 位图b1 =(位图)Bitmap.FromFile( bitmap1.bmp); 
位图b2 =(位图)Bitmap.FromFile(bitmap2.bmp);
位图b3 =(位图)Bitmap.FromFile(bitmap3.bmp);
using(Graphics g = Graphics.FromImage(b1))
{
g.DrawImage(b2,new Point(0,0));
g.DrawImage(b3,new Point(50,50));



$ b $ p
$ b

如果您的叠加层是绘制对象(文本,线条,形状等) ,那么您将创建或获取适当的画笔和笔,并使用Graphics对象将所需图像渲染到图像上。在完成任务后,务必确保处理任何一次性用品。这是使用using语句最容易完成的。


What is the fastest way to draw an on an image in .net?

I'm trying to draw an image on top of another image that have in a windows form control. I know that when I try to draw it directly using loops it takes an Eon.

Options I have heard tossed around are GDI+, Direct Draw, or DX10. I start with a bitmap of a fixed size and after applying 3+ overlays, layers, to it before it is assigned to a form object.

Thanks,

解决方案

If your overlays are images (perhaps PNG images with transparency), then the general technique is to create a Graphics object from the image onto which you'd like to draw, then render the other images onto it thusly:

    Bitmap b1 = (Bitmap) Bitmap.FromFile("bitmap1.bmp");
    Bitmap b2 = (Bitmap)Bitmap.FromFile("bitmap2.bmp");
    Bitmap b3 = (Bitmap)Bitmap.FromFile("bitmap3.bmp");
    using (Graphics g = Graphics.FromImage(b1))
    {
        g.DrawImage(b2, new Point(0, 0));
        g.DrawImage(b3, new Point(50, 50));
    }

If your overlays are drawn object (text, lines, shapes, etc.), then you would create or obtain the appropriate brushes and pens and use the Graphics object to render what you want onto the image. Always make sure you dispose of any disposables when you're done with them. This is most handily done with the using statement.

这篇关于最快的方式在窗体窗体上绘制图像的叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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