本文介绍了在C#中将不同的图像块合并为单个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将图像分割为9个块(相同的宽度和高度)后,我正在对图像进行一些处理,并按索引访问这些部分。 (对于水印项目)
I'm doing some works on image after splitting image as 9 blocks(same width and height), and access those parts by index. (For a watermarking project)
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
{
int r = bmps[cs_y, cs_x].GetPixel(y, x).R;
int g = bmps[cs_y, cs_x].GetPixel(y, x).G;
int b = bmps[cs_y, cs_x].GetPixel(y, x).B;
}
}
so现在我想要来自这9个街区的合并图像..
bmps [0,0];
bmps [0,1];
......
.....
请任何人建议任何想法来实现这个目标吗?
先谢谢!
so now I want a combine image from these 9 blocks..
bmps[0,0];
bmps[0,1];
......
.....
please any one suggest any ideas to accomplish this?
Thanks in Advance!
推荐答案
int imageWidth = bmps[0, 0].Width;
int imageHeight = bmps[0, 0].Height;
Bitmap combined = new Bitmap(imageWidth * 3, imageHeight * 3);
然后将图像绘制到新图像上:
Then draw the images onto the new image:
using (Graphics g = Graphics.FromImage(combined))
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
g.DrawImage(bmps[i, j], (float)(imageWidth * i), (float)(imageHeight * j));
}
}
}
这篇关于在C#中将不同的图像块合并为单个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!