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 android 使用system.zip单元释放资源文件

Delphi.about.com一个钩子的实现代码

Delphi wmi 取显卡gpu信息

Delphi 金木水火土 生克用法

Delphi ado 连接 excel (附excel各个版本的版本号)

Delphi 实现拦截api的钩子(hook)

Delphi响应wmi事件(响应网线断开)

Delphi 取得某一天所在的星期一及星期天

Delphi [android]获取屏幕的物理分辨率

Delphi d10.x 安卓app开发中按返回键后程序不退出程序的方法

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



打赏

取消

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

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

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

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

评论

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