想象一下,我有一个 2x2 或 3x3 图片的矩阵,我想用这 4 或 9 张图片制作一张大图片。我想在图片框上显示这张图片。
我正在开发一个 Windows Mobile 应用程序。
我怎样才能做到这一点?
编辑:将评论移至问题以进行澄清..
通常,您将图像作为这样的图片框pictureBox.image = myImage
。我想使用 4 个图像构建 myImage 。想象一下,我有一个图像并将其切成四个正方形。我想用这 4 张图像重新组合原始图像。
谢谢!
想象一下,我有一个 2x2 或 3x3 图片的矩阵,我想用这 4 或 9 张图片制作一张大图片。我想在图片框上显示这张图片。
我正在开发一个 Windows Mobile 应用程序。
我怎样才能做到这一点?
编辑:将评论移至问题以进行澄清..
通常,您将图像作为这样的图片框pictureBox.image = myImage
。我想使用 4 个图像构建 myImage 。想象一下,我有一个图像并将其切成四个正方形。我想用这 4 张图像重新组合原始图像。
谢谢!
像这样的东西:
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;
要么将 4 och 9 个 PictureBox 并排放置,要么使用 Panel 而不是 PictureBox,并使用 Graphics.DrawImage 在 Panles Paint 事件中绘制所有图像。
这应该有效,但未经测试:
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;
}