You must use the bmp1.RawImage.Description fields to determine how to copy the bytes. See http://lazarus-ccr.sourceforge.net/docs/lcl/graphtype/trawimagedescription.html for a explanation of the fields.
In your copying code you assume BitsPerPixel=24 and LineEnd=rileByteBoundary. Is that true?
Thanks,
I read the explanation, and assign 3 fields.
bmp2.RawImage.Description.Format:= ricfRGBA;
bmp2.RawImage.Description.BitsPerPixel:=BitsPerPixel;
bmp2.RawImage.Description.LineEnd:=rileDWordBoundary;
function BytesPerScanline(PixelsPerScanline, BitsPerPixel,
Alignment: Integer): Longint;
begin
Dec(Alignment);
Result := ((PixelsPerScanline * BitsPerPixel) + Alignment) and not Alignment;
Result := Result div 8;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
bmp1, bmp2:TBitmap;
ptr1, ptr2, p0:Pointer;
i,j,strideBytes,BYtesPerPixel,BitsPerPixel:integer;
begin
//if OpenDialog1.Execute then
begin
try
bmp1:=TBitmap.Create;
bmp2:=TBitmap.Create;
bmp1.LoadFromFile('test.bmp'); //OpenDialog1.FileName);
bmp2.PixelFormat := bmp1.PixelFormat;
bmp2.Width := bmp1.Width;
bmp2.Height := bmp1.Height;
BitsPerPixel :=24;
bmp2.RawImage.Description.Format:= ricfRGBA;
bmp2.RawImage.Description.BitsPerPixel:=BitsPerPixel;
bmp2.RawImage.Description.LineEnd:=rileDWordBoundary;
strideBytes := BytesPerScanline(bmp1.Width, BitsPerPixel, 32);
BytesPerPixel := BitsPerPixel div 8;
//bmp2.RawImage.Description := bmp1.RawImage.Description;
for i:=0 to bmp1.Height-1 do
begin
ptr1 := bmp1.RawImage.Data+strideBytes*i;
ptr2 := bmp2.RawImage.Data+strideBytes*i;
Move(ptr1^, ptr2^, strideBytes);
end;
bmp2.SaveToFile('aa.bmp');
finally
bmp1.Free;
bmp2.Free;
end;
end;
end;
In Windows, I guess it's 32 bits aligned, means rileDWordBoundary. I suppose Linux also the same.
if I assign the
bmp2.RawImage.Description := bmp1.RawImage.Description;
and
copy the RawImage data with the for loop, increasing pointer.
The bmp2 should be as same as bmp1, isn't it?
BTW, in Windows, the Raw Image aligned in BGRBGRBGRBGR........
Is the Linux aligned in a different manner? EX BBBBBBBBBBBBB..... GGGGGGGG.... RRRRRR..., first Blue data block, then the Green, the Red... ? ( Because the image seems have multiple shifted image.)
Thanks,
Regards,
Daniel