110,538
社区成员
发帖
与我相关
我的任务
分享
public void GetImage(Image img1, Image img2)
{
int width = img1.Width + img2.Width;
int height = img1.Height > img2.Height ? img1.Height : img2.Height;
Bitmap bmp = new Bitmap(width, height);
int x, y;
Graphics graphics = Graphics.FromImage(bmp);
bmp.Save(@"f:\test4.gif", ImageFormat.Gif);//此处可以看到创建的默认图片,一般为黑色
// Loop through the images pixels to reset color.
for (x = 0; x < bmp.Width; x++)
{
for (y = 0; y < bmp.Height; y++)
{
Color pixelColor = bmp.GetPixel(x, y);
Color newColor = Color.FromArgb(255, 255, 255);
bmp.SetPixel(x, y, newColor);
}
}
Rectangle rect1 = new Rectangle(0, 0, img1.Width, img1.Height);
Rectangle rect2 = new Rectangle(rect1.Right, 0, img2.Width, img2.Height);
graphics.DrawImage(img1, rect1, 0, 0, img1.Width, img1.Height, GraphicsUnit.Pixel);
graphics.DrawImage(img2, rect2, 0, 0, img2.Width, img2.Height, GraphicsUnit.Pixel);
graphics.Flush();
graphics.Dispose();
//bmp.MakeTransparent();//注释掉
bmp.Save(@"f:\test3.gif", ImageFormat.Gif);
bmp.Dispose();
}