首页 / 操作系统 / Linux / C#将jpg格式图片合成到bmp格式图片中
在C#中,有时为解决几个图片显示的问题,比如有一张背景图,还有一直是要显示在背景图上的图片,如何能将这2张图片合成一张图片显示呢?下面的例子提供了这样一个解决的方法,代码如下://strwinepath酒的图片//strBackPic 背景图片
private void TestPaint(string strwinepath,string strWineDetailBackPic){ //获取酒的图片,酒的图片格式为jpg格式
Image imgWine = Image.FromFile(strwinepath); //获取背景图片,背景图片格式也为jpg格式,现在读取为bmp格式
Bitmap bmp = new Bitmap(strBackPic); 获取背景图的绘图图面
Graphics g = Graphics.FromImage(bmp); //将酒的图片绘制到背景图上
g.DrawImage(imgWine, 149, 209,100,416); //将背景图片加载显示到背景上
this.BackgroundImage = bmp;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
}这样就完成了将2张图片合成了一张。