delphi图片换肤处理优化修正

原来见过一个png图像换肤处理的文章,但其中颜色处理上有些问题,特作优化修正处理,本是回复群友的问题的,所以用的是bmp图片,png图片处理原理是一样的。代码如下:
unit  Unit1 ;

interface

uses
   Windows ,  Messages ,  SysUtils ,  Variants ,  Classes ,  Graphics ,  Controls ,  Forms ,
   Dialogs ,  StdCtrls ,  ExtCtrls ;

type
   TForm1  =  class ( TForm )
     ColorBox1 :  TColorBox ;
     procedure  btn1Click ( Sender :  TObject );
     procedure  ColorBox1Select ( Sender :  TObject );
     procedure  FormPaint ( Sender :  TObject );
   private
     { Private declarations }
   public
     { Public declarations }
   end ;

var
   Form1 :  TForm1 ;

implementation
  

{$R *.dfm}

procedure  TForm1 . btn1Click ( Sender :  TObject );
var
   i ,  j :  Integer ;
   Row :  pRGBTriple ;
   Rgb  :  Longint ;
   RGB_R , RGB_G , RGB_B : Byte ;
   Gray :  Byte ;
   bmp : TBitmap ;
begin
   RGB  :=  ColorToRGB ( ColorBox1 . Selected );
   RGB_R  :=  GetRValue ( RGB );
   RGB_G  :=  GetGValue ( RGB );
   RGB_B  :=  GetBValue ( RGB );

   bmp := TBitmap . Create ;
   try
     bmp . LoadFromFile ( 'E:/Documents and Settings/siow/桌面/main.bmp' );

     for  i  :=  0  to  bmp . Height  -  1  do
     begin
       Row  :=  bmp . Scanline [ i ];
       for  j  :=  0  to  bmp . Width  -  1  do
       begin
         //灰度化
         Gray := Trunc (( Row ^. rgbtRed * 306 + Row ^. rgbtGreen * 601 + Row ^. rgbtBlue * 117 + 512 )  shr  10 );

         Row ^. rgbtRed    :=  Round ( 255  -  ( 255  -  Gray )*  ( 255 - RGB_R )/  255 );
         Row ^. rgbtGreen  :=  Round ( 255  -  ( 255  -  Gray )*  ( 255 - RGB_G )/  255 );
         Row ^. rgbtBlue   :=  Round ( 255  -  ( 255  -  Gray )*  ( 255 - RGB_B )/  255 );
         Inc ( Row );
       end ;
     end ;
     self . Canvas . StretchDraw ( bmp . Canvas . ClipRect , bmp );
   finally
     bmp . Free ;
   end ;
end ;

procedure  TForm1 . ColorBox1Select ( Sender :  TObject );
begin
   btn1Click ( nil );
end ;

procedure  TForm1 . FormPaint ( Sender :  TObject );
begin
   btn1Click ( nil );
end ;

end .
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值