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;
修改如下: 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;
当成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;
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;
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;
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;
例如:
SwithDIB(Image1.Picture.Bitmap);
Image1.Refresh;