Aplikasi Image Resizer |
Sebuah Aplikasi Foto untuk mengkompresi gambar menjadi lebih kecil dalam ukuran yang akurat
Gambar ukuran Asli |
Daftar Komponen
Rincian Codding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace pert2_aplikasi_image_resizer
{
public partial class bbuka : Form
{
private Image gambar;
public bbuka()
{
InitializeComponent();
tsize.MaxLength = 3;
tsize.Enabled = false;
}
void ubahsize()
{
if (tsize.Text != "")
{
int persen = Convert.ToInt32(tsize.Text);
int tinggi = (persen * Convert.ToInt32(ltinggi.Text)) / 100;
int lebar = (persen * Convert.ToInt32(llebar.Text)) / 100;
ltinggi.Text = Convert.ToString(tinggi);
llebar.Text = Convert.ToString(lebar);
}
}
void simpangambar()
{
int tinggi = Convert.ToInt32(ltinggi.Text);
int lebar = Convert.ToInt32(llebar.Text);
Bitmap ukuranbaru = new Bitmap(lebar, tinggi, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics gbr = Graphics.FromImage(ukuranbaru);
gbr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
gbr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
gbr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gbr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
Rectangle rect = new Rectangle(0, 0, lebar, tinggi);
gbr.DrawImage(gambar, rect);
SaveFileDialog simpan = new SaveFileDialog();
simpan.Filter = "Jpeg Format|*.Jpg";
simpan.RestoreDirectory = true;
if (simpan.ShowDialog() != DialogResult.Cancel)
{
ukuranbaru.Save(simpan.FileName);
ukuranbaru.Dispose();
MessageBox.Show("Gambar Berhasil Disimpan", "info");
}
}
void bukagambar()
{
OpenFileDialog bukagambar = new OpenFileDialog();
if (bukagambar.ShowDialog() == DialogResult.OK)
{
this.gambar = Image.FromFile(bukagambar.FileName);
picture.SizeMode = PictureBoxSizeMode.StretchImage;
picture.ImageLocation = bukagambar.FileName;
ltinggi.Text = gambar.Height.ToString();
llebar.Text = gambar.Width.ToString();
tsize.Enabled = true;
tsize.Clear();
}
}
private void button1_Click(object sender, EventArgs e)
{
bukagambar();
}
private void tsize_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
ubahsize();
}
}
private void bsimpan_Click(object sender, EventArgs e)
{
simpangambar();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace pert2_aplikasi_image_resizer
{
public partial class bbuka : Form
{
private Image gambar;
public bbuka()
{
InitializeComponent();
tsize.MaxLength = 3;
tsize.Enabled = false;
}
void ubahsize()
{
if (tsize.Text != "")
{
int persen = Convert.ToInt32(tsize.Text);
int tinggi = (persen * Convert.ToInt32(ltinggi.Text)) / 100;
int lebar = (persen * Convert.ToInt32(llebar.Text)) / 100;
ltinggi.Text = Convert.ToString(tinggi);
llebar.Text = Convert.ToString(lebar);
}
}
void simpangambar()
{
int tinggi = Convert.ToInt32(ltinggi.Text);
int lebar = Convert.ToInt32(llebar.Text);
Bitmap ukuranbaru = new Bitmap(lebar, tinggi, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics gbr = Graphics.FromImage(ukuranbaru);
gbr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
gbr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
gbr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gbr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
Rectangle rect = new Rectangle(0, 0, lebar, tinggi);
gbr.DrawImage(gambar, rect);
SaveFileDialog simpan = new SaveFileDialog();
simpan.Filter = "Jpeg Format|*.Jpg";
simpan.RestoreDirectory = true;
if (simpan.ShowDialog() != DialogResult.Cancel)
{
ukuranbaru.Save(simpan.FileName);
ukuranbaru.Dispose();
MessageBox.Show("Gambar Berhasil Disimpan", "info");
}
}
void bukagambar()
{
OpenFileDialog bukagambar = new OpenFileDialog();
if (bukagambar.ShowDialog() == DialogResult.OK)
{
this.gambar = Image.FromFile(bukagambar.FileName);
picture.SizeMode = PictureBoxSizeMode.StretchImage;
picture.ImageLocation = bukagambar.FileName;
ltinggi.Text = gambar.Height.ToString();
llebar.Text = gambar.Width.ToString();
tsize.Enabled = true;
tsize.Clear();
}
}
private void button1_Click(object sender, EventArgs e)
{
bukagambar();
}
private void tsize_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
ubahsize();
}
}
private void bsimpan_Click(object sender, EventArgs e)
{
simpangambar();
}
}
}
INGAT!!
Jika Anda kurang puas atau ingin menambahkan ide
Anda dapat mengkostumnya di Form/View code nya
Untuk keterangan lebih lanjut lihat slide
Download Slide
Download Program
1 komentar:
kenapa si picture box gak jalan ya
Posting Komentar