Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi IPicture darstellen (https://www.delphipraxis.net/48252-ipicture-darstellen.html)

muRR 22. Jun 2005 21:11


IPicture darstellen
 
Guten Abend!

Zur Zeit arbeite ich mich in die API-Programmierung ein, um meine Programme kleiner zu machen. Nun stehe ich vor dem Problem, Bilder in anderen Formaten als BMP darzustellen. Dazu habe ich bereits eine Funktion zum Laden eines IPicture's gefunden. Leider habe ich Probleme beim Darstellen dessen, was auf den Mangel an guten Beispielen (sowohl mittels der Suchfunktion hier im Forum, als auch Google) zurückzuführen ist.
Es wäre nett, wenn mir da jemand ein knappes Beispiel unter Bezug auf WM_CREATE und WM_PAINT aufzeigen könnte! Dabei kann davon ausgegangen werden, dass die Funktion
Delphi-Quellcode:
function LoadPicture(Filename: String; var pPicture: IPicture): Boolean;
vorhanden ist.

MfG

scp 22. Jun 2005 21:24

Re: IPicture darstellen
 
Einfach umwandeln...
Delphi-Quellcode:
function IPic2Bmp(pPic : IPicture) : HBITMAP;
var
  WndDC : HDC;
  hmWidth,
  hmHeight : Integer;
  rc : TRect;
  nWidth,
  nHeight : Integer;
  hOldBmp : HBITMAP;
  hdc0 : HDC;
const
  X = 0;
  Y = 0;
begin
    hdc0 := CreateIC ('DISPLAY', NIL, NIL, NIL) ;
    WndDC := CreateCompatibleDC (hdc0) ;

    if (pPic.get_Width (hmWidth ) = S_OK) and
       (pPic.get_Height(hmHeight) = S_OK) then
    begin
      nWidth := MulDiv(hmWidth ,GetDeviceCaps(WndDC,LOGPIXELSX),2540);
      nHeight := MulDiv(hmHeight,GetDeviceCaps(WndDC,LOGPIXELSY),2540);

      result := CreateCompatibleBitmap(hdc0, nWidth, nHeight);

      rc.Left  := 0;
      rc.Top   := 0;
      rc.Right := nWidth;
      rc.Bottom := nHeight;

      hOldBmp := SelectObject(WndDC, result);

      pPic.Render(WndDC,X,Y,nWidth,nHeight,0,hmHeight,hmWidth,
        -hmHeight,rc);
    end;

    DeleteDC (hdc0 );
    DeleteDC (WndDC);
end;
...oder direkt zeichnen:
Delphi-Quellcode:
procedure DrawIPic(wnd : HWND; pPic : IPicture; X, Y : Integer; wDC : HDC);
var
  WndDC : HDC;
  hmWidth,
  hmHeight : Integer;
  rc : TRect;
  nWidth,
  nHeight : Integer;
  hBmp : HBITMAP;
  hOldBmp : HBITMAP;
begin
  if Assigned(pPic) then
  begin
    If (wDC <> 0) then
      WndDC := wDC
    else
      WndDC := GetDC(wnd);

    if (pPic.get_Width(hmWidth) = S_OK) and
       (pPic.get_Height(hmHeight) = S_OK) and
       (GetClientRect(wnd,rc)) then
    begin
      nWidth := MulDiv(hmWidth ,GetDeviceCaps(WndDC,LOGPIXELSX),2540);
      nHeight := MulDiv(hmHeight,GetDeviceCaps(WndDC,LOGPIXELSY),2540);

      hBmp := CreateCompatibleBitmap(WndDC, nWidth, nHeight);
      hOldBmp := SelectObject(WndDC, hBmp);

      pPic.Render(WndDC,X,Y,nWidth,nHeight,0,hmHeight,hmWidth,
        -hmHeight,rc);
    end;

    If not (wDC <> 0) then
      ReleaseDC(wnd, WndDC);
  end;
end;

CalganX 22. Jun 2005 21:26

Re: IPicture darstellen
 
Hi,
such mal im MSDN. Das ist im Normalfall die Beste Anlaufstelle für API-Fragen.
MSDN-Library durchsuchenIPicture bringt dir z.B. folgendes Ergebnis: IPicture-Interface.

Chris

muRR 22. Jun 2005 21:30

Re: IPicture darstellen
 
Danke für die schnelle Antwort!
MSDN ist eigentlich auch die beste Antwort auf alle Fragen. Aber ich saß da jetzt mehrere Stunden dran und bin doch dankbar, dass es ne einfachere Lösung für das ganze gibt.

Ciao

scp 22. Jun 2005 21:41

Re: IPicture darstellen
 
Einfach? Relativ, wenns ein anderer schon gemacht hat. :-D Ich hab allerdings auch nur kombiniert und konvertiert, den Quelltext gabs schon in C++.


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:22 Uhr.

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