MENGGALI POTENSI AMALKAN BAKTI

Minggu, 08 Januari 2012

CONTOH PROGRAM OLAH CITRA SEDERHANA

a.    Design Form


b.    Listing Program
unit modifikasi;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtDlgs, ExtCtrls, ComCtrls;

type
  TCITRA = class(TForm)
    gambar1: TImage;
    bukagambar: TOpenPictureDialog;
    buka: TButton;
    Label1: TLabel;
    tbmerah: TTrackBar;
    tbhijau: TTrackBar;
    tbbiru: TTrackBar;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    gambar2: TImage;
    cbseragam: TCheckBox;
    Label5: TLabel;
    Label6: TLabel;
    Button1: TButton;
    procedure bukaClick(Sender: TObject);
    procedure tbmerahChange(Sender: TObject);
    procedure tbhijauChange(Sender: TObject);
    procedure tbbiruChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);

  private
  procedure aksi;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  CITRA: TCITRA;

implementation

procedure TCITRA.aksi;
var
   HS, SH: PByteArray;
   a, s, wm, wh, wb, m, h, b: Integer;
begin
   wm := tbmerah.Position;
   wh := tbhijau.Position;
   wb := tbbiru.Position;
   for s := 0 to gambar1.Picture.Height-1 do
   begin
         HS := gambar1.Picture.Bitmap.ScanLine[s];
         SH := gambar2.Picture.Bitmap.ScanLine[s];
         for a := 0 to gambar1.Picture.Width-1 do
         begin
              m := HS [3*a+2] + wm;
              if (m<0) then
                  m := 0;
              if (m>255) then
                  m := 255;
              h := HS [3*a+1] + wh;
              if (h<0) then
                  h := 0;
              if (h>255) then
                  h := 255;
              b := HS [3*a] + wb;
              if (b<0) then
                  b := 0;
              if (b>255) then
                  b := 255;
              SH [3*a+2] := m;
              SH [3*a+1] := h;
              SH [3*a] := b;
         end;
   end;
   gambar2.Refresh;
end;

{$R *.dfm}

procedure TCITRA.bukaClick(Sender: TObject);
begin
   if (bukagambar.Execute) then
   begin
       gambar1.Picture.LoadFromFile(bukagambar.FileName);
       gambar2.Picture := gambar1.Picture;
       tbmerah.Position := 0;
       tbhijau.Position := 0;
       tbbiru.Position := 0;
   end
end;

procedure TCITRA.tbmerahChange(Sender: TObject);
begin
    if cbseragam.Checked then
    begin
        tbhijau.Position := tbmerah.Position;
        tbbiru.Position := tbmerah.Position;
    end;
    aksi;
end;

procedure TCITRA.tbhijauChange(Sender: TObject);
begin
    if cbseragam.Checked then
    begin
        tbmerah.Position := tbhijau.Position;
        tbbiru.Position := tbhijau.Position;
    end;
    aksi;
end;

procedure TCITRA.tbbiruChange(Sender: TObject);
begin
    if cbseragam.Checked then
    begin
        tbmerah.Position := tbbiru.Position;
        tbhijau.Position := tbbiru.Position;
    end;
    aksi;
end;

procedure TCITRA.Button1Click(Sender: TObject);
begin
    if (Application.MessageBox('AKU MAU KELUAR!!!!!!!','ISENG',MB_YESNO)= ID_YES) then
    Close;
end;

end.

Hasil Tampilan Saat Program di Eksekusi

  •  Tampilan Awal
  • Pemanggilan Citra
  • Citra Normal
  • Warna Merah Minimum
  • Warna Merah Maksimum
  • Warna Hijau Minimum
  • Warna Hijau Maksimum
  • Warna Biru Minimum
  • Warna Biru Maksimum

Tidak ada komentar:

Posting Komentar