Kali ini kita akan coba membuat suatu aplikasi yang dimana aplikasi ini dapat mengedit foto atau gambar dengan berbagai macam fitur fitur yang mungkin masih dibilang sederhana dibandingkan dengan aplikasi editing foto lainnya semacam Photoshop, Coreldraw, Picasa, dan masih banyak lagi .
Pertama kali kita buat designnya seperti gambar diatas lalu berikan label pada setiap bagiannya seperti gambar dibawah ini :
Setelah design dibuat lanjut ke tahap pengkodingan klik dua kali pada bagian atas Form lalu koding mulai dari atas seperti kodingan dibawah ini :
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;
using System.IO;
namespace editpic
{
public partial class Form1 : Form
{
private string nmfile;
public Form1()
{
InitializeComponent();
}
//if (isi == 3)
//{
//isi = 1;
//}
OpenFileDialog ofd = new
OpenFileDialog();
ofd.Filter = "JPEG
File|*.jpg|BMP File|*bmp|PNG File|*.png";
ofd.InitialDirectory =
"D:/";
if (ofd.ShowDialog() ==
DialogResult.OK)
{
//if (isi == 1)
//{
nmfile = ofd.FileName;
pictureBox1.Image =
Image.FromFile(ofd.FileName);
//}
//else if (isi == 2)
//{
//nmfile = ofd.FileName;
//pictureBox2.Image =
Image.FromFile(ofd.FileName);
//}
//isi++;
}
Selanjutnya klik dua kali pada button Close lalu masukan kodingan dibawah :
Close();
kodingan diatas digunakan untuk menutup sebuah aplikasi
Berikutnya kodingan untuk button B/W ;
Bitmap bmg1, bmg2;
bmg1 = new
Bitmap(pictureBox1.Image);
int nR, nG, nB, nA, n;
nA = 0;
if (bmg1 != null)
{
bmg2 = new Bitmap(bmg1);
for (int i = 0; i <=
bmg1.Width - 1; i++)
{
for (int j = 0; j <=
bmg1.Height - 1; j++)
{
Color pixeColor =
bmg2.GetPixel(i,j);
nR = pixeColor.R;
nG = pixeColor.G;
nB = pixeColor.B;
nA = pixeColor.A;
n = (nR + nG + nB) / 3;
if (n > 127)
{
n = 255;
}
else
{
n = 0;
}
Color newPixel =
Color.FromArgb(n, n, n);
bmg2.SetPixel(i, j,
newPixel);
}
}
pictureBox2.Image = bmg2;
}
Button Grey :
Bitmap bmg1, bmg2;
bmg1 = new
Bitmap(pictureBox1.Image);
int nR, nG, nB, nA, n;
nA = 0;
if (bmg1 != null)
{
bmg2 = new Bitmap(bmg1);
for (int i = 0; i <=
bmg1.Width - 1; i++)
{
for (int j = 0; j <=
bmg1.Height - 1; j++)
{
Color pixeColor =
bmg2.GetPixel(i, j);
nR = (int) (pixeColor.R
* 0.29);
nG = (int) (pixeColor.G
* 0.59);
nB = (int) (pixeColor.B
* 0.11);
nA = pixeColor.A;
n = (nR + nG + nB) / 3;
Color newPixel =
Color.FromArgb(n, n, n);
bmg2.SetPixel(i, j,
newPixel);
}
}
pictureBox2.Image = bmg2;
}
selanjutnya button save untuk menyimpan File :
//Bitmap
bmp2;
//bmp2 =
new Bitmap(pictureBox2.Image);
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter
= "JPEG File|*.jpg|BMP File|*bmp|PNG File|*.png";
sfd.ShowDialog();
sfd.InitialDirectory = "D:/";
if
(sfd.FileName != "")
{
System.IO.FileStream fs =
(System.IO.FileStream)sfd.OpenFile();
pictureBox2.Image.Save
(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
fs.Close();bb
}
Button Zoom In untuk yang sebelah kanan :
pictureBox2.Top =
(int)(pictureBox2.Top - (pictureBox2.Height * 0.025));
pictureBox2.Left =
(int)(pictureBox2.Left - (pictureBox2.Width * 0.025));
pictureBox2.Height =
(int)(pictureBox2.Height + (pictureBox2.Height * 0.05));
pictureBox2.Width
Button Zoom in untuk yang sebelah kiri :
pictureBox1.Top = (int)(pictureBox1.Top - (pictureBox1.Height * 0.025));
pictureBox1.Left = (int)(pictureBox1.Left - (pictureBox1.Width *
0.025));
pictureBox1.Height
= (int)(pictureBox1.Height + (pictureBox1.Height * 0.05));
pictureBox1.Width = (int)(pictureBox1.Width + (pictureBox1.Width *
0.05));
Button Zoom Out sebelah kiri :
pictureBox1.Top =
(int)(pictureBox1.Top + (pictureBox1.Height * 0.025));
pictureBox1.Left =
(int)(pictureBox1.Left + (pictureBox1.Width * 0.025));
pictureBox1.Height =
(int)(pictureBox1.Height - (pictureBox1.Height * 0.05));
pictureBox1.Width =
(int)(pictureBox1.Width - (pictureBox1.Width * 0.05));
Button Zoom Out sebelah kanan :
pictureBox2.Top =
(int)(pictureBox2.Top + (pictureBox2.Height * 0.025));
pictureBox2.Left =
(int)(pictureBox2.Left + (pictureBox2.Width * 0.025));
pictureBox2.Height =
(int)(pictureBox2.Height - (pictureBox2.Height * 0.05));
pictureBox2.Width =
(int)(pictureBox2.Width - (pictureBox2.Width * 0.05));
Setelah semua selesai tinggal Di Debugging . Done ! :D
0 komentar:
Posting Komentar