Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   BitMap zeichnen per API (https://www.delphipraxis.net/171831-bitmap-zeichnen-per-api.html)

turboPASCAL 28. Nov 2012 09:35

AW: BitMap zeichnen per API
 
Eine Möglichkeit könnte ich mir so vorstellen:


Delphi-Quellcode:
var
  theBitmapBitArray: array of dword; // das array vom OleVariant

procedure TForm ...;
var
  theBitmap: HBITMAP;
  pBmpBits: Pointer;
  bi: BITMAPINFO;

  bmpWidth: integer;
  bmpHeight: integer;

begin
  bmpWidth := 320;
  bmpHeight := 240;

  setlength(theBitmapBitArray, bmpWidth * bmpHeight);

  // ----------------------------------------------------------- //

  ZeroMemory(@bi, sizeof(BITMAPINFO));
  with bi.bmiHeader do
  begin
    biSize := sizeof(BITMAPINFOHEADER);
    biWidth := bmpWidth;
    biHeight := -bmpHeight;
    biCompression := BI_RGB;
    biBitCount := 32;
    biPlanes := 1;
    biXPelsPerMeter := 0;
    biYPelsPerMeter := 0;
    biClrUsed := 0;
    biClrImportant := 0;
  end;

  theBitmap := CreateDIBSection(0, bi, DIB_RGB_COLORS, pBmpBits, 0, 0);

  pBmpBits := @theBitmapBitArray[0];

  SetDIBits(0, theBitmap, 0, bi.bmiHeader.biHeight * -1, pBmpBits, bi, DIB_RGB_COLORS);

  image1.Picture.Bitmap.Handle := theBitmap;
  image1.Refresh;
end;

sintronic86 5. Dez 2012 12:12

AW: BitMap zeichnen per API
 
Vielen Dank für die vielen Antworten.

Da ich aber auf dem "Zu-Fuss"-Weg nicht wirklich weitergekommen bin, habe ich mich einmal mit der Funktion StretchDIBits() genauer auseinander gesetzt.
Und siehe da: Es funktioniert.

Code:
  if FCanDraw then
  begin
    TmpBitMap       := TBitmap.Create;
    TmpBitMap.Width := FWidth_Cam;
    TmpBitMap.Height := FHeight_Cam;


    test2 := AOleVariant;

    SetStretchBltMode(TmpBitMap.Canvas.Handle, COLORONCOLOR);
    StretchDIBits(TmpBitMap.Canvas.Handle,
                  0,
                  0,
                  FWidth_Cam,
                  FHeight_Cam,
                  0,
                  0,
                  FWidth_Cam,
                  FHeight_Cam,
                  test2,
                  TmpBI,
                  DIB_RGB_COLORS,
                  SRCCOPY);



    AImage.Picture.Assign(TmpBitMap);
    TmpBitMap.Free;
  end
  else
  begin
    AImage.Picture.Assign(NIL);
  end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:34 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz