TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Saving Bitmap

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)
  • Author
    Posts
  • February 28, 2007 at 1:50 pm #22097 Reply
    nordicGod
    Participant
    • Topics - 1
    • Replies - 0
    • Total Posts - 1

    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_UINT32

    Now 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

  • Author
    Posts
Viewing 1 post (of 1 total)
Reply To: Saving Bitmap
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • TWAIN for dental imaging integration
  • PDF/R For who and where?
  • Making searchable PDF with PDF/R
  • Backward compatibility with PDF/A and traditional PDF
  • could not open the twain source. Make sure there is a valid source for your sca
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.