With this revised piece, I can now get better result, but mono.
ptr1 := R1.Data + bmp1.Width*3*i;
ptr2 := R2.Data + bmp2.Width*4*i; // make it increase every 4 byte
Move(ptr1^, ptr2^, bmp1.Width*3);
procedure TForm1.Button2Click(Sender: TObject);
var
bmp1, bmp2:TBitmap;
ptr1, ptr2:Pointer;
i:integer;
R1, R2: TRawImage;
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;
R1 := bmp1.RawImage;
bmp2.BeginUpdate;
R2 := bmp2.RawImage;
for i:=0 to bmp1.Height-1 do
begin
// something else since this won't work
ptr1 := R1.Data + bmp1.Width*3*i;
ptr2 := R2.Data + bmp2.Width*4*i;
Move(ptr1^, ptr2^, bmp1.Width*3);
// The following should do the same thing, but became whole black.
{(ptr2)^ := pByte(ptr1)^;
pByte(ptr2+1)^ := pByte(ptr1+1)^;
pByte(ptr2+2)^ := pByte(ptr1+2)^; }
end;
bmp2.EndUpdate;
bmp2.SaveToFile('../cc.bmp');
finally
bmp1.Free;
bmp2.Free;
end;
end;
end;
And the weired one is
(ptr2)^ := pByte(ptr1)^;
pByte(ptr2+1)^ := pByte(ptr1+1)^;
pByte(ptr2+2)^ := pByte(ptr1+2)^;
should same to Move(ptr1^, ptr2^, bmp1.Width*3);
but not.
I now know loaded bmp is 24 bit aligned, bmp2 is 32 bit aligned. I wonder the only problem now is I don't know how the RGB aligned in bmp2. Is it?
Daniel