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 实现从下载链接提取文件名的函数

Delphi 在ie上增添一个按钮

Delphi - 利用dll编程控制摄像头实现拍照、录制视频

Delphi中emptyparam参数被改写问题

Delphi xe5记录android应用程序(日志输出)

Delphi 安卓读写ini文件

Delphi 实现卸载windows应用程序(类似360软件管家-卸载程序)

Delphi 通用压缩单元

Delphi xe10 百度车牌识别

Delphi 主窗体最小化时不显示在任务栏

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



打赏

取消

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

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

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

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

评论

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