想象一下,我有一張2x2或3x3圖片的矩陣,我想用這4或9張圖片製作一張大圖片。我想在pictureBox上展示這張照片。C#使用各種圖片製作一張圖片
我正在開發Windows Mobile應用程序。
我該怎麼做?
編輯:移到意見,澄清問題..
通常你ASING圖像以這樣pictureBox.image = myImage
一個PictureBox。我想用4張圖像構建myImage。想象一下,我有一張照片,並用四個方塊將它剪掉。我想用這4張圖像重新組合原始圖像。
謝謝!
想象一下,我有一張2x2或3x3圖片的矩陣,我想用這4或9張圖片製作一張大圖片。我想在pictureBox上展示這張照片。C#使用各種圖片製作一張圖片
我正在開發Windows Mobile應用程序。
我該怎麼做?
編輯:移到意見,澄清問題..
通常你ASING圖像以這樣pictureBox.image = myImage
一個PictureBox。我想用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個9個PictureBoxes彼此相鄰,要麼使用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;
}
你能否提供一些更多的細節? – 2009-02-24 17:29:27