Thema: Delphi IPicture darstellen

Einzelnen Beitrag anzeigen

scp

Registriert seit: 31. Okt 2003
1.120 Beiträge
 
Delphi 7 Personal
 
#2

Re: IPicture darstellen

  Alt 22. Jun 2005, 22:24
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;
  Mit Zitat antworten Zitat