C#、様々な画像を使用して1つの画像を作ります
-
06-09-2019 - |
質問
私は2×2または3×3の画像のマトリックスを持っていると私は、これら4枚のまたは9の画像を使用して一つの大きな絵を作りたいということを想像してみてください。私は、ピクチャボックス上でこの絵を見せたい。
私はWindowsのモバイルアプリを開発しています。
私はこれを行うことができますどのように?
編集:移動のコメントは明確化のために質問する..
通常は、このようなpictureBox.image = myImage
のPictureBoxに画像をasing。私は4枚の画像を使用してMYIMAGEを構築したいです。私はイメージを持っていることを想像し、4乗の部分でそれをカット。私はオリジナルのものを再assambleするには、これらの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 PictureBoxesを互いに又はピクチャの代わりにパネルを使用しGraphics.drawImageをを用いPanlesペイントイベント内全ての画像を描画し、次の
この作業をする必要がありますが、テストされていません。
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