我写了个程序,可以做到将一张图片渐渐变成黑色的,但是当想将该黑色重新还原成图片时,却只能在该过程中变亮最后仍然是黑色的。各位高手,应该怎样解决啊,希望给出代码。谢谢先了。

解决方案 »

  1.   

    procedure Fade(const BMP:TImage; Pausetime:integer);
      var
        BytesPor: integer;   //定义变量,存储图片的宽
        wei,hei: integer;
        p1: pByteArray;       //定义变量,存储象素
        countar: integer;
    begin
        BytesPor := Abs ( Integer(BMP.Picture.Bitmap.ScanLine[1])-
                                Integer(BMP.Picture.Bitmap.ScanLine[0]));
    //得到图片的宽度    for countar := 1 to 256 do
        begin
          for hei := 0 to BMP.Picture.Bitmap.Height - 1 do
    //从上到下进行扫描
          begin
            P1 := BMP.Picture.Bitmap.ScanLine[hei];
    //得到每一行中的各个象素
            for wei := 0 to BytesPor - 1 do
              if P1^[wei] >0 then P1^[wei] := P1^[wei]-1;
    //象素的RGB值-1
          end;
          Sleep(Pausetime);            //  暂停指定的时间
          BMP.Refresh;                   // 更新原来的图片
        end;
    end;procedure Re_Fade(const BMP:TImage; BMP_TEMP : TImage;Pausetime:integer);
      var
        BytesPor: integer;   //定义变量,存储图片的宽    wei,hei: integer;
        p1: pByteArray;       //定义变量,存储象素
        p1_temp :  pByteArray;
        countar: integer;
    begin
        BytesPor := Abs ( Integer(BMP.Picture.Bitmap.ScanLine[1])-
                                Integer(BMP.Picture.Bitmap.ScanLine[0]));//得到图片的宽度    for countar := 1 to 256 do
        begin
          for hei := 0 to BMP.Picture.Bitmap.Height - 1 do
    //从上到下进行扫描
          begin
            P1 := BMP.Picture.Bitmap.ScanLine[hei];
            p1_temp:= BMP_TEMP.Picture.Bitmap.ScanLine[hei];//得到原图象素值
    //得到每一行中的各个象素
            for wei := 0 to BytesPor - 1 do
              if (P1^[wei] <255) and (P1^[wei]<p1_temp^[wei]) then P1^[wei] := P1^[wei]+1
                  else
                    P1^[wei]:=p1_temp^[wei];
    //象素的RGB值+1
          end;
          Sleep(Pausetime);            //  暂停指定的时间
          BMP.Refresh;                   // 更新原来的图片
        end;
    end;