Thema: Delphi 18bit Bilder erstellen??

Einzelnen Beitrag anzeigen

NicoDE
(Gast)

n/a Beiträge
 
#12

Re: 18bit Bilder erstellen??

  Alt 16. Nov 2005, 18:34
Zitat von Simon6785:
Also es ist 116160Bytes groß und 176x220px.
Das wären genau 3 Byte pro Pixel (kein Header).
Test-Code könnte so aussehen:
Delphi-Quellcode:
function Bitmap18ToHandle(Source: Pointer; Width, Heigth: Integer): HBITMAP;
type
  PPixel18 = ^TPixel18;
  TPixel18 = record
    Data: array [0..2] of Byte; // Three bytes?
  end;
var
  DevContext: HDC;
  BitmapInfo: TBitmapInfo;
  BitmapBits: PRGBTriple;
  x, y: Integer;
  SourceBits: PPixel18;
begin
  Result := 0;
  DevContext := CreateCompatibleDC(0);
  if DevContext = 0 then
    Exit;
  try
    ZeroMemory(@BitmapInfo, SizeOf(TBitmapInfo));
    with BitmapInfo.bmiHeader do
    begin
      biSize := SizeOf(TBitmapInfoHeader);
      biWidth := Width;
      biHeight := -Heigth; // top-down
      biPlanes := 1;
      biBitCount := 24;
      biCompression := BI_RGB;
    end;
    Result := CreateDIBSection(0, BitmapInfo, DIB_RGB_COLORS,
      Pointer(BitmapBits), 0, 0);
    if Result = 0 then
      Exit;
    try
      SourceBits := Source;
      for y := 1 to Heigth do
      begin
        for x := 1 to Width do
        begin
          //FIXME: Pixel conversion...?
          // ______bb bbbbgggg ggrrrrrr
          // rrrrrrrr gggggggg bbbbbbbb
          BitmapBits.rgbtRed :=
            ((SourceBits.Data[0] and $3F) );
          BitmapBits.rgbtGreen :=
            ((SourceBits.Data[0] ) shr 6) or
            ((SourceBits.Data[1] and $0F) shl 2);
          BitmapBits.rgbtBlue :=
            ((SourceBits.Data[1] ) shr 4) or
            ((SourceBits.Data[2] and $03) shl 4);
          Inc(BitmapBits);
          Inc(SourceBits);
        end;
        // Scanline alignment on DWORD boundaries
        BitmapBits := Pointer((Cardinal(BitmapBits) + 3) and Cardinal(not 3));
      end;
    except
      DeleteObject(Result);
      Result := 0;
    end;
  finally
    DeleteDC(DevContext);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create();
  try
    Stream.LoadFromFile('pwroff04.ani');
    Image1.Picture.Bitmap.Handle := Bitmap18ToHandle(Stream.Memory, 176, 220);
  finally
    Stream.Free();
  end;
end;
  Mit Zitat antworten Zitat