Aplikasi Image Resize

Aplikasi Image Resize

Nama : Ahmad Farhan Zuhdi
NIM : 13141008
Kelas : 13.6A.37 (BSI PEMUDA)
Tugas Network Programming II

 Gambar 4.1. Tampilan Image Resize

Gambar 4.2. Choose Picture

 Gambar 4.3.Choose Directories Save


 Gambar 4.4. Type Picture

Gambar 4.5. Image was Resize

Gambar 4.6. Image has been Saved



Coding Project :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Image_Resize
{
    public partial class Form1 : Form
    {
        Image img;
        string[] extend = { ".PNG", ".JPEG", ".JPG", ".GIF"};

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < extend.Length; i++)
                comboBox.Items.Add(extend[i]);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "images | *.png;*.jpg;*.jpeg;*.gif";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtch.Text = ofd.FileName;
                img = Image.FromFile(ofd.FileName);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
                txtsv.Text = fbd.SelectedPath;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int w = Convert.ToInt32(txtw.Text), h = Convert.ToInt32(txth.Text);
            img = Resize(img, w, h);
            ((Button)sender).Enabled = false;
            MessageBox.Show("Image resized");
        }

        Image Resize(Image image, int w, int h)
        {
            Bitmap bmp = new Bitmap(w, h);
            Graphics graphic = Graphics.FromImage(bmp);
            graphic.DrawImage(image, 0, 0, w, h);
            graphic.Dispose();

            return bmp;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int dot = 0, slash = 0;
            for (int j = txtch.Text.Length - 1; j >= 0; j--)
                if(txtch.Text[j] == '.')
                    dot = j;
                else if (txtch.Text[j] == '\\')
                {
                    slash = j;
                    break;
                }

            img.Save(txtsv.Text + "\\" + txtch.Text.Substring(slash + 1, dot - slash - 1) + extend[comboBox.SelectedIndex]);
            ((Button)sender).Enabled = false;
            MessageBox.Show("Image Saved");
        }
    }
}
Share:

0 komentar:

Posting Komentar

Cari Blog Ini

websiteku19.blogspot.co.id

Diberdayakan oleh Blogger.

Aplikasi Image Resize

Aplikasi Image Resize Nama : Ahmad Farhan Zuhdi NIM : 13141008 Kelas : 13.6A.37 (BSI PEMUDA) Tugas Network Programming II  Gambar...