|
写了一个用GetDataLineStart获取像素并复制的函数,但是图像复制以后出现了斑马状纵向条纹,请大家帮忙看看。
写此函数的目的只是摸索用内存法正确访问像素,为以后的数字图像处理创造条件。
function CopyBitMap2//逐像素复制一个位图,使用GetDataLineStart函数
(InBMP: TBitMap; var OutBMP: TBitMap; var runs: string): boolean;
var
TempBMP: TBitMap;
IntfImg1, IntfImg2: TLazIntfImage;
ImgHandle, ImgMaskHandle:HBitMap;
px, py: Integer;
Row1, Row2: PRGBTripleArray;
begin
IntfImg1:=TLazIntfImage.Create(0, 0);
IntfImg2:=TLazIntfImage.Create(0, 0);
TempBMP:=TBitMap.Create;
//将TBitMap载入到Lazarus的图形类IntfImg
//必须完成载入操作以后才能正常操作IntfImg
IntfImg1.LoadFromBitmap(InBMP.Handle, InBMP.MaskHandle);
IntfImg2.LoadFromBitmap(TempBMP.Handle, TempBMP.MaskHandle);
//IntfImg1的内容复制到IntfImg2
IntfImg2.Width:=IntfImg1.Width;
IntfImg2.Height:=IntfImg1.Height;
for py:=0 to IntfImg2.Height-1 do
begin
Row1:=IntfImg1.GetDataLineStart(py);//类似Delphi的Scanline
Row2:=IntfImg2.GetDataLineStart(py);
for px:=0 to IntfImg1.Width do
begin
//Row2^[px]:=Row1^[px];
//以下语句为逐像素的色彩赋值
Row2^[px].rgbtBlue:=Row1^[px].rgbtBlue;
Row2^[px].rgbtGreen:=Row1^[px].rgbtGreen;
Row2^[px].rgbtRed:=Row1^[px].rgbtRed;
end;
end;
//IntfImg2的内容复制给OutBMP
//过程是CreateBitmaps,然后给Handle和MaskHandle赋值
IntfImg1.CreateBitmaps(ImgHandle, ImgMaskHandle, false);
IntfImg2.CreateBitmaps(ImgHandle, ImgMaskHandle, false);
OutBMP.Handle:=ImgHandle;
OutBMP.MaskHandle:=ImgMaskHandle;
IntfImg1.Free;
IntfImg2.Free;
TempBMP.Free;
runs:='OK';
result:=true;
end; |
|