图片合并
static public void LRImageMerge(Image Img1, Image Img2)
{
int imgHeight, imgWidth = Img1.Width;
imgWidth += Img2.Width;
imgHeight = Img1.Height > Img2.Height ? Img1.Height : Img2.Height;
Bitmap joinedBitmap = new Bitmap(imgWidth, imgHeight);
Graphics graph = Graphics.FromImage(joinedBitmap);
graph.DrawImage(Img1, 0, 0, Img1.Width, Img1.Height);
graph.DrawImage(Img2, Img1.Width, 0, Img2.Width, Img2.Height);
Image img = joinedBitmap;
SaveFileDialog SaveFileDialog1 = new SaveFileDialog
{
Title = "图片另存为",
Filter = "jpg图片|*.JPG|gif图片|*.GIF|png图片|*.PNG|jpeg图片|*.JPEG",
FilterIndex = 3,
RestoreDirectory = true
};
if (img != null)
{
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
string pictureName = SaveFileDialog1.FileName;
using (MemoryStream mem = new MemoryStream())
{
Bitmap bmp = new Bitmap(img);
bmp.Save(pictureName, img.RawFormat);
bmp.Dispose();
MessageBox.Show("图片保存成功!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("没有图片信息!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
img.Dispose();
}
static public void UDImageMerge(Image Img1, Image Img2)
{
int imgHeight = Img1.Height, imgWidth;
imgHeight += Img2.Height;
imgWidth = Img1.Width > Img2.Width ? Img1.Width : Img2.Width;
Bitmap joinedBitmap = new Bitmap(imgWidth, imgHeight);
Graphics graph = Graphics.FromImage(joinedBitmap);
graph.DrawImage(Img1, 0, 0, Img1.Width, Img1.Height);
graph.DrawImage(Img2, 0, Img1.Height, Img2.Width, Img2.Height);
Image img = joinedBitmap;
SaveFileDialog SaveFileDialog1 = new SaveFileDialog
{
Title = "图片另存为",
Filter = "jpg图片|*.JPG|gif图片|*.GIF|png图片|*.PNG|jpeg图片|*.JPEG",
FilterIndex = 3,
RestoreDirectory = true
};
if (img != null)
{
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
string pictureName = SaveFileDialog1.FileName;
using (MemoryStream mem = new MemoryStream())
{
Bitmap bmp = new Bitmap(img);
bmp.Save(pictureName, img.RawFormat);
bmp.Dispose();
MessageBox.Show("图片保存成功!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("没有图片信息!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
img.Dispose();
}
static public void ImageMerge(List<Image> Img)
{
int imgHeight = Img[0].Height, imgWidth = Img[0].Width;
for(int i = 1; i< 4; i++)
{
imgWidth = imgWidth > Img[i].Width ? imgWidth : Img[i].Width;
imgHeight = imgHeight > Img[i].Height ? imgHeight : Img[i].Height;
}
Bitmap joinedBitmap = new Bitmap(imgWidth<<1, imgHeight<<1);
Graphics graph = Graphics.FromImage(joinedBitmap);
graph.DrawImage(Img[0], 0, 0, Img[0].Width, Img[0].Height);
graph.DrawImage(Img[1], imgWidth, 0, Img[1].Width, Img[1].Height);
graph.DrawImage(Img[2], 0, imgHeight, Img[2].Width, Img[2].Height);
graph.DrawImage(Img[3], imgWidth, imgHeight, Img[3].Width, Img[3].Height);
Image img = joinedBitmap;
SaveFileDialog SaveFileDialog1 = new SaveFileDialog
{
Title = "图片另存为",
Filter = "jpg图片|*.JPG|gif图片|*.GIF|png图片|*.PNG|jpeg图片|*.JPEG",
FilterIndex = 3,
RestoreDirectory = true
};
if (img != null)
{
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
string pictureName = SaveFileDialog1.FileName;
using (MemoryStream mem = new MemoryStream())
{
Bitmap bmp = new Bitmap(img);
bmp.Save(pictureName, img.RawFormat);
bmp.Dispose();
MessageBox.Show("图片保存成功!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("没有图片信息!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
img.Dispose();
}