Fastest way to draw an overlay on an image in windows forms

荒凉一梦 提交于 2019-12-14 03:58:06

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/1288428/fastest-way-to-draw-an-overlay-on-an-image-in-windows-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!