Forums › TWAIN Classic › Saving Bitmap
- This topic has 0 replies, 1 voice, and was last updated 14 years, 1 month ago by nordicGod.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
Hi at all,
here is my problem:
I wrote a C++ class which scans an image. The Scan-Process is successfull, i guess, but i can´t save the DIB Bitmap.Well, I got to the Point “TWRC_XFERDONE” an there i will do that:
SendMessage(hWnd, WM_TW_IMAGE, 0, hBitmap);
hBitmap is the TW_UINT32Now I will save the Bitmap at the Case WM_TW_IMAGE:
HANDLE hBitmap_n = GlobalLock((void*)lParam);
BITMAP bmp;
if(GetObject(hBitmap_n, sizeof(BITMAP), (LPSTR)&bmp)==0) MessageBox(NULL,"fehler geobj","fehler",MB_OK);
HDC hdcBmp; hdcBmp = CreateCompatibleDC(hdc);
SelectObject(hdcBmp, hBitmap_n);
bool b = BitBlt(hdc,150,120, bmp.bmWidth,bmp.bmHeight, (HDC)hBitmap_n, 0,0, SRCCOPY);
if (b==false) MessageBox(NULL,"fehler","fehler7",MB_OK);
// Infoheader
BITMAPINFO infoheader;
infoheader.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
infoheader.bmiHeader.biWidth = 500; // Breite in Pixeln
infoheader.bmiHeader.biHeight = 500; // Höhe in Pixeln
infoheader.bmiHeader.biPlanes = 1;
infoheader.bmiHeader.biBitCount = 24; // Farbtiefe in bits
infoheader.bmiHeader.biCompression = 0;
infoheader.bmiHeader.biSizeImage = 0;
infoheader.bmiHeader.biXPelsPerMeter = 0;
infoheader.bmiHeader.biYPelsPerMeter = 0;
infoheader.bmiHeader.biClrUsed = 0;
infoheader.bmiHeader.biClrImportant = 0;
// Platz für die Pixeldaten reservieren
int* bitmap = new int[500*500*3]; // Breite*Höhe*Farbtiefe (Bytes)
// Fileheader
BITMAPFILEHEADER fileheader;
fileheader.bfType = 19778; // 'BM'
fileheader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(bitmap); // Gesamtgröße der Datei
fileheader.bfReserved1 = 0;
fileheader.bfReserved2 = 0;
fileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); // ab hier Pixel
//##############
// Create a memory DC to draw in
//HDC dc = GetDC(hWnd); // old: hWnd
HDC dc = CreateDC(NULL, NULL, NULL, NULL);
HDC mem = CreateCompatibleDC(dc);
// Create a bitmap and link it to the memory dc
HBITMAP hbitmap = CreateCompatibleBitmap(dc, 500, 500);
//##############
//dc old /*new_bmpHandle (struct HBITMAP__ *)*/
if (GetDIBits(mem, (HBITMAP)hBitmap_n, 0, 500, bitmap, (BITMAPINFO*)&infoheader, DIB_RGB_COLORS)==0)
//if (SetDIBits(mem, hBIT/*(HBITMAP)lParam/*hbitmap*/, 0, 500, bitmap, (BITMAPINFO*)&infoheader, DIB_RGB_COLORS)==0)
MessageBox(NULL,"fehler","fehler0",MB_OK);
// Eine neue Datei erstellen bzw eine bestehende öffnen
HANDLE hfile = CreateFile("d:\cmap.bmp", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, 0);
// Die Daten in die Datei schreiben
DWORD dummy;
WriteFile(hfile, &fileheader, 14, &dummy, NULL);
WriteFile(hfile, &infoheader, 40, &dummy, NULL);
WriteFile(hfile, bitmap, 750000, &dummy, NULL);
// Aufräumen
DeleteObject(hBitmap_n);
ReleaseDC(hWnd, dc);
CloseHandle(hfile);
The Bitmap is grey…not the Bitmap i scanned.
Hope, you will find an error, im confused…….sorry for my bad english & thanks for helping me
-
AuthorPosts
Viewing 1 post (of 1 total)