![]() |
Übersetzung C++ -> Delphi
Hallo
ich habe eine dll die ein LCD Display ansteuert. Leider ist der beispiel Code in C++ geschrieben mit dem ich nicht viel anfangen kann. Wie muss ich das Bitmap an die Funktion PSUC_Frame2LCD aus der dll übergeben. Die Informationen über das Bitmap die ausgegeben werden sind nicht so wichtig. Hier ist der der Teil aus dem Code.
Code:
Und der Teil aus der header Datei:
TCHAR *FileNames[] = {
TEXT("PIC10.BMP"), TEXT("LION.BMP"), TEXT("PIC6.BMP"), NULL }; int index = 0; while(1) { TCHAR* pFileName = FileNames[index]; if( pFileName == NULL ) break; printf("Test Graphic %s\n",pFileName); HBITMAP hbmp = NULL; HDC hdc = NULL; do { hbmp = (HBITMAP)LoadImage(NULL,pFileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE); if( hbmp == INVALID_HANDLE_VALUE ) break; HDC hdc = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL); if (hdc == NULL) break; BITMAPINFO BMPInfo; memset(&BMPInfo,0,sizeof(BMPInfo)); BMPInfo.bmiHeader.biSize = sizeof(BMPInfo); int r = GetDIBits(hdc,hbmp,0,0,NULL,&BMPInfo,DIB_RGB_COLORS); if( r == 0 ) break; printf(" biSize %d/%d\n",BMPInfo.bmiHeader.biSize,sizeof(BMPInfo)); printf(" biSizeImage %d\n",BMPInfo.bmiHeader.biSizeImage); printf(" biWidth %d\n",BMPInfo.bmiHeader.biWidth); printf(" biHeight %d\n",BMPInfo.bmiHeader.biHeight); printf(" biBitCount %d\n",BMPInfo.bmiHeader.biBitCount); printf(" biPlanes %d\n",BMPInfo.bmiHeader.biPlanes); printf(" biClrUsed %d\n",BMPInfo.bmiHeader.biClrUsed); if( BMPInfo.bmiHeader.biPlanes != 1 ) break; if( BMPInfo.bmiHeader.biHeight != 64 ) break; if( BMPInfo.bmiHeader.biWidth != 128 ) break; if( BMPInfo.bmiHeader.biBitCount != 1 && BMPInfo.bmiHeader.biBitCount != 24 && BMPInfo.bmiHeader.biBitCount != 32 ) break; int BMPInfoSize = sizeof(BITMAPINFOHEADER); if( BMPInfo.bmiHeader.biCompression == BI_BITFIELDS ) BMPInfoSize += 12; else BMPInfoSize += BMPInfo.bmiHeader.biClrUsed * sizeof(RGBQUAD); BITMAPINFO* pBMPInfo = (BITMAPINFO*) ( new BYTE[BMPInfoSize] ); if( pBMPInfo != NULL ) { *pBMPInfo = BMPInfo; } BYTE* pBuffer = new BYTE[BMPInfo.bmiHeader.biSizeImage]; if( pBuffer != NULL ) { memset(pBuffer,0,BMPInfo.bmiHeader.biSizeImage); r = GetDIBits(hdc,hbmp,0,64,pBuffer,pBMPInfo,DIB_RGB_COLORS); printf( " GetDIBits %d\n",r); PSUC_Frame2LCD(handle,pBuffer,BMPInfo.bmiHeader.biSizeImage); } } while(0); if( hbmp != NULL ) CloseHandle(hbmp); if( hdc != NULL ) CloseHandle(hdc); index += 1; Sleep(5000); }
Code:
extern int PSUCAPI_API PSUC_Frame2LCD(PSUC_HANDLE psucHandle,BYTE* pBuffer,int BufferSize);
|
Re: Übersetzung C++ -> Delphi
Delphi-Quellcode:
* ungetested
type
ULONG_PTR = Cardinal; TPsucHandle = ULONG_PTR; function Bitmap2LCD(Psuc_Handle: TPsucHandle; Bitmap: TBitmap): integer; var bmp: tagBitmap; Frame2LCDResult: integer; begin Result := 0; if not assigned(Bitmap) then begin Result := -1; // Bitmap ist nicht vorhanden/erstellt exit; end; if not ((Bitmap.Width = 128) and (Bitmap.Height = 64)) then begin Result := -2; // Bitmapgroesse stimmt nicht exit; end; if Bitmap.PixelFormat <> pf24Bit then // nur RGB zulassen Bitmap.PixelFormat := pf24Bit; if Bitmap.HandleType <> bmDIB then // nur DIB-Format zulassen Bitmap.HandleType := bmDIB; ZeroMemory(@bmp, sizeof(tagBitmap)); GetObject(Bitmap.Handle, sizeof(tagBitmap), @bmp); Frame2LCDResult := PSUC_Frame2LCD(Psuc_Handle, bmp.bmBits, 64 * 128 * 3); // ImageSize = Höhe = 64 * Breite = 128 * RGB=3 // if Frame2LCDResult <> 0 then // hier Fehler auswerten siehe Docu. // Result := -3; // Bitmap(roh)daten konnten nicht übertragen werden end; ![]() Um was für ein Display handelt es sich denn ? |
Re: Übersetzung C++ -> Delphi
dabei ist diese Ganze Funktion eher "sinnlos"
wichtig ist ja "nur" due Funktion PSUC_Frame2LCD und wie man ihr das Bild mitgibt. die hiergezeigte Funktion zeigt ja nur auf'm Desktop einige Infos zum Bild an und das Wichtigere darin: es wird in einer Schleife (welche man ja so selber nicht braucht) je ein Bild geladen, geprüft ob es bestimmte Bedingungen erfüllt > Breite = 128 Pixel > Höhe = 64 Pixel > Pixelformat = 1, 24 oder 32 Bit und dann wird es nur noch als Handle im Format DIB an die Funktion übergeben. das Wichtige "Woher kommt das Handle zum LCD (Psuc_Handle)" fehlt hier |
Re: Übersetzung C++ -> Delphi
Ja der Code funktioniert super danke. Endlich klappts ich versuchs schon
seit mehreren tagen. Es ist so ein kleines USB Farb-LCD 128x64 das ich mal bei eBay gekauft hab. Das Psuc_Handle kommt aus einer anderen Funktion aus der dll. |
Re: Übersetzung C++ -> Delphi
@himitsu, meinste meine ? :stupid:
|
Re: Übersetzung C++ -> Delphi
im Prinzip hätte man diese Funktion kürzen können
[edit] ups, hab grad gemerkt, daß du es ja schon auf eine Funktion gekürzt hast, welcher man nur noch das Bitmap übergibt :oops: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:11 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