GetPixelData example for Delphi
{ This example uses GetPixelData and PutPixelData to swap the R and G values for a particular pixel.
This example will work only with 24, 32, 48 and 64-bit bitmaps}
Procedure TForm1.SwapRGBtoBGR( nRow: Integer; nCol: Integer);
var
uVal: Cardinal;
aPixel: Array [0..3] of L_UCHAR; // make it large enough for both bitmap types
bPixel: Array [0..3] of L_UINT16; // make it large enough for both bitmap types
pPixel: Pointer;
begin
if((LEADImage1.BitmapBits = 24) Or
(LEADImage1.BitmapBits = 32)) then
begin
pPixel:= @aPixel;
LEADImage1.GetPixelData(pPixel, nRow, nCol, 4);
// swap the R and B values
uVal:= aPixel[0]; aPixel[0] := aPixel[2]; aPixel[2] := uVal;
// put back the transformed pixel
LEADImage1.PutPixelData(pPixel, nRow, nCol, sizeof(aPixel));
end
else
if((LEADImage1.BitmapBits = 48) Or
(LEADImage1.BitmapBits = 64)) then
begin
pPixel:= @bPixel;
LEADImage1.GetPixelData(pPixel, nRow, nCol, 4);
// swap the R and B values
uVal:= aPixel[0]; aPixel[0]:= aPixel[2]; aPixel[2]:= uVal;
// put back the transformed pixel
LEADImage1.PutPixelData(pPixel, nRow, nCol, sizeof(aPixel));
end;
end;
{ This example uses GetPixelData and PutPixelData to swap the R and G values for a particular pixel.
This example will work only with 24, 32, 48 and 64-bit bitmaps}
Procedure TForm1.SwapRGBtoBGR( nRow: Integer; nCol: Integer);
var
uVal: Cardinal;
aPixel: Array [0..3] of L_UCHAR; // make it large enough for both bitmap types
bPixel: Array [0..3] of L_UINT16; // make it large enough for both bitmap types
pPixel: Pointer;
begin
if((LEADImage1.BitmapBits = 24) Or
(LEADImage1.BitmapBits = 32)) then
begin
pPixel:= @aPixel;
LEADImage1.GetPixelData(pPixel, nRow, nCol, 4);
// swap the R and B values
uVal:= aPixel[0]; aPixel[0] := aPixel[2]; aPixel[2] := uVal;
// put back the transformed pixel
LEADImage1.PutPixelData(pPixel, nRow, nCol, sizeof(aPixel));
end
else
if((LEADImage1.BitmapBits = 48) Or
(LEADImage1.BitmapBits = 64)) then
begin
pPixel:= @bPixel;
LEADImage1.GetPixelData(pPixel, nRow, nCol, 4);
// swap the R and B values
uVal:= aPixel[0]; aPixel[0]:= aPixel[2]; aPixel[2]:= uVal;
// put back the transformed pixel
LEADImage1.PutPixelData(pPixel, nRow, nCol, sizeof(aPixel));
end;
end;