Arif widiyanto

mind, passions, spirit and hopes

Delphi Mengkonversi bitmap ke sepia atau greyscale

Ditulis oleh arifw di/pada Kamis, 24 April 2008


Function bmptosepia(const bmp: TBitmap; depth: Integer): Boolean;

var

color,color2:longint;

r,g,b,rr,gg:byte;

h,w:integer;

begin

for h := 0 to bmp.height do

begin

for w := 0 to bmp.width do

begin

color:=colortorgb(bmp.Canvas.pixels[w,h]);

r:=getrvalue(color);

g:=getgvalue(color);

b:=getbvalue(color);

color2:=(r+g+b) div 3;

bmp.canvas.Pixels[w,h]:=RGB(color2,color2,color2);

color:=colortorgb(bmp.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;

bmp.canvas.Pixels[w,h]:=RGB(rr,gg,b);

end;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

bmptosepia(image1.picture.bitmap, 20);

end;


Tinggalkan Balasan

XHTML: Anda dapat gunakan tag ini: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>