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 getfilehashmd5获取文件 hashmd5值

Delphi快速地删除一个目录

Delphi 写日志函数

Delphi query1 导出csv txt

Delphi 操作webbrowser 元素值

DelphiDelphi提升进程权限为debug权限

Delphi ipnumberipv4

xe7提示找不到sharedactivitycontext函数

Delphi安卓动态切换本地主题

Delphi webbrowser1 设置获取编码

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



打赏

取消

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

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

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

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

评论

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