© Gruenthal

Gruenthal

  • Home
  • .Net
    • C#
  • JavaScript
    • jQuery
    • Sonstige
    • Spiele
    • Text
  • JavaApplet
    • Grafik
    • Menüs
    • Sonstige
    • Spiele
    • Text
  • Powershell
    • IIS
    • Sonstiges
    • TFS
    • WMI
    • XML
  • Tutorials
  • Flash
    • ActionScript
    • Spiele
    • Text
DotNet
  • C#
ImageToThumbnail
Es soll ein Bild geladen und per Trackbar skalliert werden

Das Laden der Grafik erfolgt über einen eindachen OpenDialog, die Grafik wird in einem HiddenImage abgelegt, damit die Skalierung per Trackbar zugriff auf das Originalbild hat.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace UploadThumbnail
{
    public partial class FormImageToThumbnain : Form
    {
        private int OrgWidth { get; set; }
        private int OrgHeight { get; set; }
    

        public FormImageToThumbnain()
        {
            InitializeComponent();
        }

        private void btUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog opendialog = new OpenFileDialog();

            opendialog.Filter = "Image files(*.jpg; *.jpeg; *.gif)| *.jpg; *.jpeg; *.gif";

            if (opendialog.ShowDialog() == DialogResult.OK)
            {

                Bitmap img = new Bitmap(opendialog.FileName);
                OrgWidth = img.Width;
                OrgHeight = img.Height;

                pbUpload.Image = img.GetThumbnailImage(350, 350, null, new IntPtr());

                opendialog.RestoreDirectory = true;
                CreateThumb();
            }
        }

        private void tBar_Scroll(object sender, EventArgs e)
        {
            label1.Text = "Prozent:" + tBar.Value;
            if (OrgWidth > 0 && OrgHeight > 0)
                CreateThumb();
        }

        private void CreateThumb()
        {
            Image imag = pbUpload.Image;
            decimal inPrc = tBar.Value ;
            int widthPerc = (int)Math.Abs(OrgWidth * inPrc/100);
            int heightPerc = (int)Math.Abs(OrgHeight * inPrc/100);

            pbThumbnail.Image = imag.GetThumbnailImage(widthPerc, heightPerc, null, new IntPtr());
            pbThumbnail.Width = widthPerc;
            pbThumbnail.Height = heightPerc;

            lblOutput.Text = string.Format("\nOriginalgröße Width:{0} Height:{1}", OrgWidth, OrgHeight);
            lblOutput.Text += string.Format("\nThumbgröße Width:{0} Height:{1}", widthPerc, heightPerc);
            this.Height = heightPerc + 100;
            this.Width = widthPerc+250;
         
        }
    }
}



Und so sieht es aus:
ImageToThumbnail
Views: 1529

© 1997 - 2019 - WebmasterBox

  • Info
  • Impressum