Halaman

Tampilkan postingan dengan label My program. Tampilkan semua postingan
Tampilkan postingan dengan label My program. Tampilkan semua postingan

Jumat, 03 Februari 2012

Negatif Gambar Pada Delphi




unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    image1: TImage;
    image2: TImage;
    btn1: TButton;
    btn2: TButton;
    lbl1: TLabel;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
  var
x, y: Integer;
p: pbytearray;
begin

image2.Height := image1.Picture.Bitmap.Height;
image2.Width := image1.Picture.Bitmap.Width;

for y := 0 to image1.Picture.Bitmap.Height  - 1 do
begin

p := image1.Picture.bitmap.ScanLine[y];
for x := 0 to image1.Picture.Bitmap.Width - 1 do
begin

image2.Canvas.pixels[x, y] := rgb(
255 - (p[x * 3] - 4),
255 - (p[x * 3] - 2),
255 - (p[x * 3] - 3));


end;

end;

end;

procedure TForm1.btn2Click(Sender: TObject);
begin
Application.Terminate;
end;
end.

Sephia Pada Delphi



unit project2;

interface

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

type
  TForm1 = class(TForm)
    image1: TImage;
    image2: TImage;
    Intensitas: TLabel;
    edit1: TEdit;
    Sepia: TButton;
    Exit: TButton;
    procedure SepiaClick(Sender: TObject);
    procedure ExitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SepiaClick(Sender: TObject);
var
color:longint;
r,g,b,rr,gg:byte;
h,w, depth:integer;
begin
// Menentukan nilai intensitasnya
depth := StrToInt(Edit1.Text);
// assign gambar ke image2 dari image1
image2.Picture.Bitmap := image1.Picture.Bitmap;
for h := 0 to image2.Picture.Bitmap.height do
begin
for w := 0 to image2.Picture.Bitmap.width do
begin
// membuat tampilan dengan warna sephia
color:=colortorgb(image2.Picture.Bitmap.Canvas.pixels[w,h]);
r:=getrvalue(color);
g:=getgvalue(color);
b:=getbvalue(color);
rr:=r+(depth*2);
gg:=g+depth;
if rr <= ((depth*2)-1) then
rr:=255;
if gg <= (depth-1) then
gg:=255;
image2.Picture.Bitmap.canvas.Pixels[w,h]:=RGB(rr,gg,b);
end;
end;
end;

procedure TForm1.ExitClick(Sender: TObject);
begin
 Application.Terminate;
end;

end.

Grayscale Pada Delphi

Lama tidak buat posting, hari ini ingin share program yang pernah dibuat dulu, semoga bisa bermanfaat...
program ini menggunkan software delphi, untuk mengubah warna gambar berupa grayscale..
listing program grayscale:

unit Unit01;

interface

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

type
  TForm1 = class(TForm)
    image1: TImage;
    image2: TImage;
    Grayscale: TButton;
    Exit: TButton;
    procedure GrayscaleClick(Sender: TObject);
    procedure ExitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure imagegrayscale(AnImage: TImage; var output : TImage);
 var
JPGImage: TJPEGImage;
BMPImage: TBitmap;
MemStream: TMemoryStream;
begin
BMPImage := TBitmap.Create;
try
BMPImage.Width := AnImage.Picture.Bitmap.Width;
BMPImage.Height := AnImage.Picture.Bitmap.Height;

JPGImage := TJPEGImage.Create;

try
JPGImage.Assign(AnImage.Picture.Bitmap);
JPGImage.CompressionQuality := 100;
JPGImage.Compress;
JPGImage.Grayscale := True;

BMPImage.Canvas.Draw(0, 0, JPGImage);

MemStream := TMemoryStream.Create;

try
BMPImage.SaveToStream(MemStream);

MemStream.Position := 0;

output.Picture.Bitmap.LoadFromStream(MemStream);
output.Refresh;

finally
MemStream.Free;

end;

finally
JPGImage.Free;

end;

finally
BMPImage.Free;

end;
end;

procedure TForm1.GrayscaleClick(Sender: TObject);
begin
ImageGrayScale(Image1, Image2);
end;

procedure TForm1.ExitClick(Sender: TObject);
begin
Application.Terminate;
end;
end.