简体   繁体   English

在1个图片盒中加载2张图片-C#

[英]Load 2 images in 1 picturebox - C#

How can I load 2 Images in one PictureBox ? 如何在一个PictureBox中加载2张图像?

Here is an example: 这是一个例子:

http://postimg.org/image/l78kth897/ http://postimg.org/image/l78kth897/

Thank you so much. 非常感谢。

You can use Graphics.DrawImage() to draw any image anywhere inside a PictureBox or any other control for that matter. 您可以使用Graphics.DrawImage()在PictureBox或任何其他控件中的任何位置绘制任何图像。 If you're writing your own control, override OnPaint() . 如果要编写自己的控件,请重写OnPaint() If you want to use an existing PictureBox, simply use its Paint event to do this: 如果要使用现有的PictureBox,只需使用其Paint事件即可:

e.Graphics.DrawImage(YourImageObjectHere, ...);  
e.Graphics.DrawImage(YourSecondImageObjectHere, ...);

GDI+ already supports transparency channel, so if your images have transparent areas, they'll draw just like the sample image you have posted. GDI +已经支持透明度通道,因此,如果您的图像具有透明区域,它们将像您发布的示例图像一样进行绘制。 DrawImage() has over a dozen overloads, using which you can control several aspects of how an image is drawn. DrawImage()具有十几个重载,使用它们可以控制图像绘制的多个方面。 The simplest one takes the image object and the position to draw at. 最简单的方法是获取图像对象和绘制位置。

Remember that an image object is an object of System.Drawing.Image or one of its derived classes. 请记住,图像对象是System.Drawing.Image的对象或其派生类之一。 If all you have is the path of the image, you should use Image.FromFile() to create an Image object from that image file first. 如果只拥有图像的路径,则应首先使用Image.FromFile()从该图像文件创建一个Image对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM