我目前正致力于图像处理应用。我把'Main'PictureBox作为画布。我想将一些PictureBox插入'Main'PictureBox并将所有Picture合并为一个Image然后将其保存到png。这是我的代码。有人可以帮我完成这项任务吗?
Bitmap bmp = new Bitmap(pictureEdit.Width, pictureEdit.Height);
bmp = (Bitmap)pictureEdit.Image;
foreach (Control c in pictureEdit.Controls)
{
if (c is Functions.pictureEdit)
{
using (var bitmap = new Bitmap(pictureEdit.Image.Width, pictureEdit.Image.Height)) {
using (var canvas = Graphics.FromImage(bitmap)) {
canvas.DrawImage(bmp, new Rectangle(0, 0, pictureEdit.Image.Width, pictureEdit.Image.Height));
canvas.DrawImage(((Functions.pictureEdit)c).img, new Rectangle(0, 0, pictureEdit.Image.Width, pictureEdit.Image.Height));
canvas.Save();
}
bitmap.Save(@"D:\Test\new.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
}
答案 0 :(得分:0)
希望您将图像组合在一起是可以的 以下代码执行此操作
私有位图CombineBitmap(List lstImages,int width,int height)
{
int iTilesPerWidth = 5;
//create a bitmap to hold the combined image
Bitmap finalImage = new System.Drawing.Bitmap(width, height);
//get a graphics object from the image so we can draw on it
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
PointF point1 = new PointF(0, 0);
int nCount = 1;
foreach (Bitmap BM in lstImages)
{
//512, 256
g.DrawImage(BM, point1);
point1.X += BM.Width;
if (nCount % iTilesPerWidth == 0)
{
point1.X = 0;
point1.Y += BM.Height;
}
nCount++;
}
}
return finalImage;
}