想象一下,我有一个2x2或3x3图片的矩阵,我想用这些4或9张图片制作一张大图片。我想在pictureBox上显示这张照片。
我正在开发Windows Mobile App。
我该怎么做?
编辑:将评论移至问题澄清..
通常情况下,您将图像作为此pictureBox.image = myImage
的图片框。我想用4张图片构建myImage。想象一下,我有一个图像并将其切成四个方块。我想用这4张图片重新编写原始图像。
谢谢!
答案 0 :(得分:5)
这样的事情:
Bitmap bitmap = new Bitmap(totalWidthOfAllImages, totalHeightOfAllImages);
using(Graphics g = Graphics.FromBitmap(bitmap))
{
foreach(Bitmap b in myBitmaps)
g.DrawImage(/* do positioning stuff based on image position */)
}
pictureBox1.Image = bitmap;
答案 1 :(得分:0)
将4 och 9 PictureBox彼此相邻放置或使用Panel而不是PictureBox,并使用Graphics.DrawImage在Panles Paint事件中绘制所有图像。
答案 2 :(得分:0)
这应该有效,但未经测试:
private Image BuildBitmap(Image[,] parts) {
// assumes all images are of equal size, assumes arrays are 0-based
int xCount = parts.GetUpperBound(0) + 1;
int yCount = parts.GetUpperBound(0) + 1;
if (xCount <= 0 || yCount <= 0)
return null; // no images to join
int width = parts[0,0].Width;
int height = parts[0,0].Height;
Bitmap newPicture = new Bitmap(width * xCount, height * yCount);
using (Graphics g = Graphics.FromImage(newPicture)) {
for (int x = 0; x < xCount; x++)
for (int y = 0; y < yCount; y++)
g.DrawImage(parts[x, y], x * width, y & height);
}
return newPicture;
}