Sei sulla pagina 1di 3

unit UnitUtama;

interface

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

type
TFormUtama = class(TForm)
PanelAtas: TPanel;
ButtonAmbilCitra: TButton;
StatusBar: TStatusBar;
OpenPictureDialog: TOpenPictureDialog;
ButtonCrop: TButton;
procedure ButtonAmbilCitraClick(Sender: TObject);
procedure Olah;
procedure ButtonCropClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
FormUtama: TFormUtama;

implementation

uses UnitCitra;

var
FormHasil: TFormCitra;

{$R *.dfm}

procedure TFormUtama.ButtonAmbilCitraClick(Sender: TObject);


var
fc: string;
begin
if (OpenPictureDialog.Execute) then
begin
if (FormCitra = nil) then
Application.CreateForm(TFormCitra, FormCitra);
FormCitra.Image.Picture.LoadFromFile(
OpenPictureDialog.FileName);
FormCitra.ClientHeight :=
FormCitra.Image.Picture.Height;
FormCitra.ClientWidth :=
FormCitra.Image.Picture.Width;
FormCitra.ClientHeight :=
FormCitra.Image.Picture.Height;
case (FormCitra.Image.Picture.Bitmap.PixelFormat) of
pf1bit : fc := 'biner';
pf8bit : fc := 'keabuan';
pf24bit : fc := 'true color';
end;
StatusBar.SimpleText := OpenPictureDialog.FileName
+ ' (' + IntToStr(FormCitra.Image.Picture.Width)
+ 'x' + IntToStr(FormCitra.Image.Picture.Height)
+ ', ' + fc + ')';
end;
end;

procedure TFormUtama.Olah;
var
x, y, x1, y1, w, h, w1, h1: integer;
PC, PH: PByteArray;
Ki, Ri, Gi, Bi, Ko, Ro, Go, Bo: array of array of byte;
begin
w := FormCitra.Image.Picture.Width;
h := FormCitra.Image.Picture.Height;
w1 := (xR-xL);
h1 := (yB-yT);
FormHasil.Image.Picture.Bitmap.Width := w1;
FormHasil.Image.Picture.Bitmap.Height := h1;
if (FormCitra.Image.Picture.Bitmap.PixelFormat = pf8bit)
then
begin
SetLength(Ki, w, h);
SetLength(Ko, w1, h1);
for y := 0 to h-1 do
begin
PC := FormCitra.Image.Picture.Bitmap.ScanLine[y];
for x := 0 to w-1 do
Ki[x, y] := PC[x];
end;
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := x1+xL;
y := y1+yT;
Ko[x1, y1] := Ki[x, y];
end;
for y1 := 0 to h1-1 do
begin
PH := FormHasil.Image.Picture.Bitmap.ScanLine[y1];
for x1 := 0 to w1-1 do
PH[x1] := Ko[x1, y1];
end;
Ki := nil;
Ko := nil;
end;
if (FormCitra.Image.Picture.Bitmap.PixelFormat = pf24bit)
then
begin
SetLength(Ri, w, h);
SetLength(Gi, w, h);
SetLength(Bi, w, h);
SetLength(Ro, w1, h1);
SetLength(Go, w1, h1);
SetLength(Bo, w1, h1);
for y := 0 to h-1 do
begin
PC := FormCitra.Image.Picture.Bitmap.ScanLine[y];
for x := 0 to w-1 do
begin
Bi[x, y] := PC[3*x];
Gi[x, y] := PC[3*x+1];
Ri[x, y] := PC[3*x+2];
end;
end;
for x1 := 0 to w1-1 do
for y1 := 0 to h1-1 do
begin
x := x1+xL;
y := y1+yT;
Ro[x1, y1] := Ri[x, y];
Go[x1, y1] := Gi[x, y];
Bo[x1, y1] := Bi[x, y];
end;
for y1 := 0 to h1-1 do
begin
PH := FormHasil.Image.Picture.Bitmap.ScanLine[y1];
for x1 := 0 to w1-1 do
begin
PH[3*x1] := Bo[x1, y1];
PH[3*x1+1] := Go[x1, y1];
PH[3*x1+2] := Ro[x1, y1];
end;
end;
Ri := nil;
Gi := nil;
Bi := nil;
Ro := nil;
Go := nil;
Bo := nil;
end;
end;

procedure TFormUtama.ButtonCropClick(Sender: TObject);


begin
if (FormCitra = nil) then
begin
ShowMessage('Ambil dulu citra yang akan diolah');
exit;
end;
if ((xL = xR) or (yT = yB)) then
begin
xL := 0;
yT := 0;
xR := FormCitra.Image.Picture.Width-1;
yB := FormCitra.Image.Picture.Height-1;
end;
if (FormHasil = nil) then
Application.CreateForm(TFormCitra, FormHasil);
FormHasil.Caption := 'Citra Hasil';
FormHasil.Image.Picture := FormCitra.Image.Picture;
FormHasil.Top := FormCitra.Top;
FormHasil.Left := FormCitra.Left+FormCitra.Width;
Olah;
FormHasil.ClientHeight :=
FormHasil.Image.Picture.Height;
FormHasil.ClientWidth :=
FormHasil.Image.Picture.Width;
FormHasil.ClientHeight :=
FormHasil.Image.Picture.Height;
end;

end.

Potrebbero piacerti anche