Forum: PC-Programmierung c# Bitmap Object


von mirki (Gast)


Lesenswert?

moin moin,

wie kann man ein bitmap, was in eine picturebox kommt, skalieren ?

mirki

von mirki (Gast)


Lesenswert?

Das Problem ist gelöst.

Bitmap img = new Bitmap(openFileDialog1.FileName);

        //skaliert das Bild
        double dblHeight = img.Height;
        double dblWidth = img.Width;
        double dblFactor = 0.0;
        if (dblHeight >= dblWidth)
          dblFactor = dblHeight / pictureBox1.Height;
        else
          dblFactor = dblWidth / pictureBox1.Width;

        pictureBox1.Width = pictureBox1.Height *2;
        dblHeight = dblHeight / dblFactor;
        dblWidth = dblWidth / dblFactor;

        Bitmap result = new Bitmap((int) dblWidth,(int) dblHeight);
        Graphics g = Graphics.FromImage(result);
        g.DrawImage(img,new Rectangle(0,0,(int) dblWidth, (int)
dblHeight),
          new Rectangle(0,0,img.Height,img.Width),GraphicsUnit.Pixel);
        pictureBox1.Image = result;

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.