Como dibujar en los pixels de un bitmap con punteros (mas rapido que pixel(]) y como pasar de TColor a RGB
2004-07-14 00:00:00
function RGB2TColor(r,g,b : integer) : TColor;
begin
Result:=b shl 16+g shl 8+r;
end;
procedure TColor2RGB(c : tcolor; var r : integer; var g : integer; var b : integer);
begin
r:=c and $FF;
g:=(c and $ff00) shr 8;
b:=(c and $ff0000) shr 16;
end;
function TColor2R(c : Tcolor) : integer;
begin
result:=c and$FF;
end;
function TColor2G(c : Tcolor) : integer;
begin
result:=(c and $ff00) shr 8;
end;
function TColor2B(c : Tcolor) : integer;
begin
result:=(c and $ff0000) shr 16;
end;
// Pset(bitmap1,200,200,RGB2Color(0,0,64));
// Dibujaria un punto azul oscuro en el punto 200,200 del bitmap1
procedure Pset(bitmap : TBitmap; X,Y : Integer; c : TColor);
var
pPixels : PByteArray;
begin
pPixels:=Bitmap.ScanLine[Y];
pPixels[X*3]:=TColor2B(c);
pPixels[X*3+1]:=TColor2G(c);
pPixels[X*3+2]:=TColor2R(c);
end;
function Preset(bitmap : TBitmap; X,Y : Integer) : TColor;
var
pPixels : PByteArray;
begin
pPixels := Bitmap.ScanLine[Y];
result:=RGB2TColor(pPixels[X*3+2],pPixels[X*3+1],pPixels[X*3]);
end;
He actualizado ligeramente las funciones de conversión de formatos de colores.