delphi编程实现图像的淡入浅出


本文整理自网络,侵删。

 下面是关键代码,需要引用的单元,自己添加上去就可以~

function IntToByte(i:Integer): Byte;
begin
if i > 255 then Result := 255
else if i < 0 then Result := 0
else Result := i;
end;

procedure Lightness1(var clip: tbitmap; Amount: Integer);
var
p0: pbytearray;
r, g, b, p, x, y: Integer;
begin
for y := 0 to clip.Height - 1 do
begin
p0 := clip.scanline[y];
for x := 0 to clip.Width - 1 do
begin
r := p0[x * 3];
g := p0[x * 3 + 1];
b := p0[x * 3 + 2];
p0[x * 3] := IntToByte(r + ((255 - r) * Amount) div 255);
p0[x * 3 + 1] := IntToByte(g + ((255 - g) * Amount) div 255);
p0[x * 3 + 2] := IntToByte(b + ((255 - b) * Amount)div 255);
end;
end;
end;


procedure Lightness(var clip: tbitmap; Amount: Integer);
var
p0: pbytearray;
r, g, b, p, x, y: Integer;
n: array[0..255] of Integer;
begin
for y := 0 to 255 do
n[y] := IntToByte(y + ((255 - y) * Amount) div 255);
for y := 0 to clip.Height - 1 do
begin
p0 := clip.scanline[y];
for x := 0 to clip.Width - 1 do
begin
b := p0[x * 3];
g := p0[x * 3 + 1];
r := p0[x * 3 + 2];
p0[x * 3] := n[b];
p0[x * 3 + 1] := n[g];
p0[x * 3 + 2] := n[r];
end;
end;

end;


procedure TForm1.TrackBar1Change(Sender: TObject);
var
vBitmap:TBitmap;
begin
vBitmap:=TBitmap.Create;
try
vBitmap.Assign(Image1.Picture.Graphic);
vBitmap.PixelFormat:=pf8bit;
Image1.Picture.SaveToFile('c:\test1.bmp');
Lightness(vBitmap,TrackBar1.Position);
vBitmap.SaveToFile('c:\test2.bmp');
Image2.Picture.Bitmap.Assign(vBitmap);
finally
vBitmap.Free;
end;
end;

相关阅读 >>

Delphi xe 横屏竖屏的管理

Delphi仿qq窗口抖动的代码

Delphi 从网页里下载图片的程序

Delphi 调用批处理

进程防杀Delphi版(dll部分)

Delphi 读取全网站链接

Delphi 简单的封装messagebox对话框

Delphi打开网址链接的四种方法

trichedit 是一个标准的rtf编辑器

Delphi xe6 �c使用android的zlib

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...