我已经编码为 4x 图像将合并为单个图像,尺寸将相加,以便最终图像确保它始终有空间容纳所有 4 个图像。// Determining width and heightint widthF = Math.Max((globeVar.width1 + globeVar.width2), (globeVar.width3 + globeVar.width4));int heightF = Math.Max((globeVar.height1 + globeVar.height2), (globeVar.height3 + globeVar.height4));//Getting drawing objects readyImage img = new Bitmap(widthF, heightF);Graphics drawing = Graphics.FromImage(img);//paint the background to check where image is not mergeddrawing.Clear(Color.Blue);drawing.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;// Draw the image to the graphics to create the new image // Which will be used in the onpaint background drawing.DrawImage(globeVar.image1, 0, 0);drawing.DrawImage(globeVar.image2, (img.Width) / 2, 0);drawing.DrawImage(globeVar.image3, 0, (img.Height) / 2);drawing.DrawImage(globeVar.image4, (img.Width) / 2, (img.Height) / 2);drawing.Save();img.Save(@globeVar.savePath, ImageFormat.Png); drawing.Dispose();现在代码实际上适用于以下 4 个图像:https://imgur.com/a/4yrPWIs但是当我使用这些图像时:https://imgur.com/a/YBSEyBN合并变成这样:https://imgur.com/a/bhnkoi1我到底错过了什么?
1 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
我自己找到了答案。看起来 DrawImage 方法没有考虑图像的默认大小。所以我必须定义它们的原始大小才能成功合并。
我刚刚更新:
drawing.DrawImage(globeVar.image1, 0, 0, globeVar.width1, globeVar.height1);
drawing.DrawImage(globeVar.image2, (img.Width) / 2, 0, globeVar.width2, globeVar.height2);
drawing.DrawImage(globeVar.image3, 0, (img.Height) / 2, globeVar.width3, globeVar.height3);
drawing.DrawImage(globeVar.image4, (img.Width) / 2, (img.Height) / 2, globeVar.width4, globeVar.height4);
从文档:
我之前用过: DrawImage(Image, Int32, Int32)
我现在使用: DrawImage(Image, Int32, Int32, Int32, Int32)
- 1 回答
- 0 关注
- 178 浏览
添加回答
举报
0/150
提交
取消