这是我的函数,可是结果只是图像变的稍微模糊,红色和蓝色并没有对调。错在哪儿了。各位高手赐教!

解决方案 »

  1.   

    procedure SwithDIB(var clip: TBitmap);
    var
      p0: PByteArray;
      x, y: Integer;
      iValue: Integer;
    begin
      for y := 0 to clip.Height - 1 do
      begin
        p0 := clip.scanline[y];
        for x := 0 to clip.Width - 1 do
        Begin
          iValue := p0[x * 3];
          p0[x * 3] := p0[x * 3 + 2];
          p0[x * 3 + 2] := iValue;
        end;
      end;
    end;
      

  2.   

    修改如下:
    procedure SwithDIB(clip: TBitmap);
    var
      p0: PByteArray;
      x, y: Integer;
      iValue: Integer;
    begin
      clip.PixelFormat := pf32bit;
      for y := 0 to clip.Height - 1 do
      begin
        p0 := clip.scanline[y];
        for x := 0 to clip.Width - 1 do
        Begin
          iValue := p0[x * 4];
          p0[x * 4] := p0[x * 4 + 2];
          p0[x * 4 + 2] := iValue;
        end;
      end;
    end;
      

  3.   

    当成24bit来处理也可以:
    procedure SwithDIB(clip: TBitmap);
    var
      p0: PByteArray;
      x, y: Integer;
      iValue: Byte;
    begin
      clip.PixelFormat := pf24bit;
      for y := 0 to clip.Height - 1 do
      begin
        p0 := clip.scanline[y];
        for x := 0 to clip.Width - 1 do
        Begin
          iValue := p0[x * 3];
          p0[x * 3] := p0[x * 3 + 2];
          p0[x * 3 + 2] := iValue;
        end;
      end;
    end;
      

  4.   

    是24bit的图像,clip.PixelFormat := pf24bit;这句我在调用前已经使用了。效果是不对的。
      

  5.   

    奇怪,你的上面一个处理32bit效果是对的。
      

  6.   

    处理完了之后, 那个Bitmap所在对象有没有Refresh?
    例如:
    SwithDIB(Image1.Picture.Bitmap);
    Image1.Refresh;