Ver Mensaje Individual
  #3  
Antiguo 20-10-2005
rounin rounin is offline
Miembro
 
Registrado: sep 2005
Posts: 43
Reputación: 0
rounin Va por buen camino
Un pixel - un bit.

Código Delphi [-]
 
function GetMonoPixel(P: PArrayOfByte; I: Integer): TColor;
const Colors: array[0..1]of TColor = (clBlack, clWhite);
var NByte, nbit: Integer;
    ByteN: Byte;
begin
  NByte := I div 8;
  nbit := 7 - (I - NByte*8);
  ByteN := P^[NByte];
  Result := Colors[  (ByteN shr nbit) and 1  ];
end;

procedure SetMonoPixel(P: PArrayOfByte; I: Integer; Value: TColor);
var NByte, nbit: Integer;
    ByteN: Byte;
begin
  NByte := I div 8;
  nbit := 7 - (I - NByte*8);
  ByteN := P^[NByte];
  case Value of
    clWhite: ByteN := ByteN or (1 shl nbit);
    clBlack: ByteN := ByteN and (not(1 shl nbit))
    else raise Exception.Create('Only white or black!');
  end;
  P^[NByte] := ByteN;
end;
Responder Con Cita