Frage

Stellen Sie sich vor, dass ich eine Matrix von 2x2 oder 3x3 Bilder haben, und ich möchte mit diesen 4 oder 9 Bilder ein großes Bild machen. Ich möchte auf einem PictureBox dieses Bild zeigen.

Ich bin ein Windows Mobile-App zu entwickeln.

Wie kann ich das tun?

Edit: Verschoben Kommentare zur Klärung in Frage ..

Normalerweise Asing Sie ein Bild auf einem PictureBox wie diese pictureBox.image = myImage. Ich möchte myImage mit 4 Bildern bauen. Stellen Sie sich vor, dass ich ein Bild haben und schneiden Sie es in vier quadratische Stücke aus. Ich möchte diese vier Bilder verwenden, um das Original erneut assamble.

Danke!

War es hilfreich?

Lösung

So etwas wie folgt aus:

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;

Andere Tipps

entweder Platz 4 och 9 PictureBox nebeneinander oder ein Panel anstelle eines PictureBox verwenden und alle Bilder im Falle panles Farbe zeichnen Graphics.DrawImage verwendet wird.

Das sollte funktionieren, ist aber nicht getestet:

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;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top