Bildbreite in % ?



  • Hiermit werden die Dateinamen aus einem "Bilder"-Ordner ausgelesen und als Thumbs + Bildbreite
    und Bildhöhe in Pixel angezeigt:

    private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    string filePath = Application.StartupPath + "\\Bilder\";
    string fileName = Path.Combine(filePath, (string) listBox1.SelectedItem);

    _image = System.Drawing.Image.FromFile(fileName);

    int max = Math.Min(this.pictureBox.Width, this.pictureBox.Height);
    int width = _image.Width;
    int height = _image.Height;
    // determine the size for the thumbnail image
    if (_image.Width > max || _image.Height > max)
    {
    if (_image.Width > _image.Height)
    {
    width = max;
    height = (int) (_image.Height * max / _image.Width);
    }
    else
    {
    width = (int) (_image.Width * max / _image.Height);
    height = max;
    }
    }
    // set feedback information
    this.pictureBox.Image = new Bitmap(_image, width, height);
    this.labelImageSize.Text = string.Format("{0} x {1}", _image.Size.Width, _image.Size.Height);
    }

    Ich möchte aber die Bildbreite und Bildhöhe in % wissen??? Um dann später zu sagen: Wenn die Bildbreite 150% größer
    ist als die Bildhöhe dann tu das...

    Wie geht das???



  • Wenn du den Quotienten aus Höhe und Breite nimmst, also (Hoehe/Breite), dann hast du doch das Verhältnis (*100 = in Prozent)...



  • Das ging ja schnell. Danke für die Lösung.
    Manchmal sieht man den Baum vor lauter Bäumen nicht...



  • Du meintest wohl "Wald vor lauter Bäumen nicht" 🙂



  • 😉

    Ja natürlich.

    Hab schneller gedacht als geschrieben... (soll vorkommen)


Anmelden zum Antworten