![]() |
Aus DIB ein Bitmap erzeugen
Liste der Anhänge anzeigen (Anzahl: 1)
Ich möchte Informationen aus dem Internet Explorer in mein Programm via Drag and Drop ziehen. Text + HTML klappen prima, nur mit den Bildern komme ich nicht zurecht.
Es wird immer nur ein weisses Rechteck angezeigt...
Delphi-Quellcode:
Was mach ich falsch????
procedure TForm1.HandleDIB( dataObj : IDataObject; fetc : TFormatEtc );
var p : pointer; stgm : TSTGMEDIUM; BMIH : TBITMAPINFO; bmp :HBITMAP; _HDC, hDC : windows.HDC; begin {Make certain the data rendering is available} if( dataObj.QueryGetData( fetc ) = NOERROR ) then begin {Get the data} dataObj.GetData( fetc, stgm ); {Lock the global memory handle to get a pointer to the data} BMIH := TBITMAPINFO(GlobalLock(stgm.hGlobal)^); with bmih.bmiHeader do bmp:=CreateBitmap (biWidth,biHeight,biPlanes,biBitCount,@bmih.bmiColors); _HDC := GetDC(Self.Handle); hDC := CreateCompatibleDC(_HDC); SelectObject(hDC, bmp); BitBlt (hDC, 0, 0, bmih.bmiHeader.biWidth, bmih.bmiHeader.biHeight, img.Canvas.Handle, 0, 0, cmSrcCopy); // Nur zum Füllen von bmp BitBlt(_HDC, 0, 0, bmih.bmiHeader.biWidth, bmih.bmiHeader.biHeight, hDC, 0, 0, cmSrcCopy); {Finished with the pointer} GlobalFree( stgm.hGlobal ); {Free the memory} ReleaseStgMedium( stgm ); end; end; Danke Axel |
Re: Aus DIB ein Bitmap erzeugen
Delphi-Quellcode:
Eine Lösung kann ich Dir leider nicht präsentieren, nur eine Vermutung. Der Wert für bmp ist 0, also wurde kein Bitmap erstellt. Die Werte für bmiColor sind auch 0,0,0,0. Kann sein, dass der Farbraum nicht stimmt!?
with bmih.bmiHeader do bmp:=CreateBitmap (biWidth,biHeight,biPlanes,biBitCount,@bmih.bmiColors);
|
Re: Aus DIB ein Bitmap erzeugen
Du kopierst bei der Zuweisung nur den TBitmapHeader und nicht die Bits, du musst mit Zeigern arbeiten!
Passe die markierten Zeilen an:
Delphi-Quellcode:
Nachträge:
procedure TForm1.HandleDIB( dataObj : IDataObject; fetc : TFormatEtc );
var p : pointer; stgm : TSTGMEDIUM; BMIH : PBITMAPINFO; // <-- HIER bmp :HBITMAP; _HDC, hDC : windows.HDC; begin {Make certain the data rendering is available} if( dataObj.QueryGetData( fetc ) = NOERROR ) then begin {Get the data} dataObj.GetData( fetc, stgm ); {Lock the global memory handle to get a pointer to the data} BMIH := PBITMAPINFO(GlobalLock(stgm.hGlobal)); // <-- HIER with bmih.bmiHeader do bmp:=CreateBitmap (biWidth,biHeight,biPlanes,biBitCount,@bmih.bmiColors); _HDC := GetDC(Self.Handle); hDC := CreateCompatibleDC(_HDC); SelectObject(hDC, bmp); BitBlt (hDC, 0, 0, bmih.bmiHeader.biWidth, bmih.bmiHeader.biHeight, img.Canvas.Handle, 0, 0, cmSrcCopy); // Nur zum Füllen von bmp BitBlt(_HDC, 0, 0, bmih.bmiHeader.biWidth, bmih.bmiHeader.biHeight, hDC, 0, 0, cmSrcCopy); {Finished with the pointer} GlobalFree( stgm.hGlobal ); {Free the memory} ReleaseStgMedium( stgm ); end; end; 1. Du solltest noch ein paar Resourcenschutzblöcke reinpacken (try...finally). 2. Da du schon eine DIB hast kannst du die auch mit CreateDIBitmap erzeugen. 3. Beim ersten BitBlt überschreibst du BMP mit dem Inhalt aus dem Image-Canvas. 4. Du selektierst BMP nicht wieder aus dem DC heraus. 5. Du gibst BMP nirgendwo wieder frei (DeleteObject). 6. Du gibst hDC nirgendwo wieder frei (DeleteDC). 7. Du gibst _HDC nirgendwo wieder frei (ReleaseDC). |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:23 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