C#中使用的各种图片制作一个图片
-
06-09-2019 - |
题
假设自己需要的2×2 3×3或画面的矩阵和我想使利用这些4张或9图片中的一个大图。我要显示在一个PictureBox这张图片。
我正在开发一个Windows移动应用。
我怎样才能做到这一点?
编辑:移到评价澄清的问题..
通常你ASING的图像以这样pictureBox.image = myImage
一个PictureBox。我想用4个图像建立MYIMAGE。想象一下,我有一个图像,并把它剪四个方形片。我想用这些4个图像重新assamble原之一。
谢谢!
解决方案
像这样:
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个PictureBoxes彼此相邻或使用面板代替一个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;
}
不隶属于 StackOverflow