Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:05:59+00:00 2026-05-24T10:05:59+00:00

I am using DevIL in my vc++ application. I need to save an image.

  • 0

I am using DevIL in my vc++ application. I need to save an image. I have the bitmap image which is generated programatically. How can I save the image in a png format to a specific location?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:06:00+00:00Added an answer on May 24, 2026 at 10:06 am
    BOOL CCreateHtml::CreateImage(IHTMLDocument2 *pDoc,LPCTSTR szDestFilename,CSize srcSize)
    {
        IHTMLDocument3* pDocument3 = NULL;
        IHTMLDocument2* pDocument  = NULL;
        IHTMLElement2* pElement2   = NULL;
        IHTMLElement* pElement     = NULL;
        IViewObject2* pViewObject  = NULL;
        IDispatch* pDispatch       = NULL;
        IViewObject* pViewObj = NULL;
    
        HRESULT hr;
    
        long bodyHeight;
        long bodyWidth;
        long rootHeight;
        long rootWidth;
        long height;
        long width;
        CImage img;
            if(FAILED(m_pBrowser->get_Document(&pDispatch)))
            return FALSE;
        if(FAILED(pDispatch->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument)))
            return FALSE;
        if(FAILED(pDocument->get_body(&pElement)))
            return FALSE;
        if(FAILED(pElement->QueryInterface(IID_IHTMLElement2,(void**)&pElement2)))
            return FALSE;
        if(FAILED(pElement2->get_scrollHeight(&bodyHeight)))
            return FALSE;
        if(FAILED(pElement2->get_scrollWidth(&bodyWidth)))
            return FALSE;
        if(FAILED(pDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pDocument3)))
            return FALSE;
        if(FAILED(pDocument3->get_documentElement(&pElement)))
            return FALSE;
        if(FAILED(pElement->QueryInterface(IID_IHTMLElement2,(void**)&pElement2)))
            return FALSE;
        if(FAILED(pElement2->get_scrollHeight(&rootHeight)))
            return FALSE;   
        if(FAILED(pElement2->get_scrollWidth(&rootWidth)))
            return FALSE;
    
        HBITMAP m_hBmp;
        width = bodyWidth;
        height = rootHeight > bodyHeight ? rootHeight : bodyHeight;
    
        if(width > 2000)
            width = 2000;
        if(height > 2000)
            height = 2000;
    
        MoveWindow(0,0,width,height,TRUE);
        ::MoveWindow(m_hwndWebBrowser,0,0,width,height,TRUE);
    
        if(FAILED(m_pBrowser->QueryInterface(IID_IViewObject2,(void**)&pViewObject)))
            return FALSE;
    
        CDC *cdcMain = GetDC();
        HDC hdcMain = *cdcMain;
        HDC hdcMem = CreateCompatibleDC(hdcMain);
        m_hBmp = CreateCompatibleBitmap(hdcMain,width,height);
        SelectObject(hdcMem,m_hBmp);
    
        RECTL rcBounds = { 0, 0, width, height };
    
        hr = pViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL,hdcMain,hdcMem, &rcBounds, NULL, NULL, 0);
    
    
            //Here is the code for saving an image as png
    
        CreateImage();
        ILHANDLE devHandle = m_hBmp;
        ilInit();
        ilBindImage(iluGenImage());
        ilLoadImage("123.bmp");
    
        ilSaveImage("abc1.png");
    
        pViewObject->Release();
        return TRUE;
    }
    
    
    //This method is used to save a  .bmp image as a bitmap stream
    
    BOOL CCreateHtml::CreateImage()
    {
        BITMAP bmp;
        HBITMAP hBmp = m_hBmp;
        int n= ::GetObject( hBmp,sizeof( BITMAP ),&bmp );
        BITMAPFILEHEADER   bmfHeader;    
        BITMAPINFOHEADER   bi;
    
    
        bi.biSize = sizeof(BITMAPINFOHEADER);    
        bi.biWidth = bmp.bmWidth;    
        bi.biHeight = bmp.bmHeight;  
        bi.biPlanes = 1;    
        bi.biBitCount = 32;    
        bi.biCompression = BI_RGB;    
        bi.biSizeImage = 0;  
        bi.biXPelsPerMeter = 0;    
        bi.biYPelsPerMeter = 0;    
        bi.biClrUsed = 0;    
        bi.biClrImportant = 0;
    
        DWORD dwBmpSize = ((bmp.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmp.bmHeight;
        HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); 
        char *lpbitmap = (char *)GlobalLock(hDIB);  
        int m = GetDIBits((HDC)GetDC(), hBmp, 0,
            (UINT)bmp.bmHeight,
            lpbitmap,
            (BITMAPINFO *)&bi, DIB_RGB_COLORS);
    
        CString str = "captureqwsx.bmp";
        LPCSTR fNam  =(LPCSTR)(LPCTSTR) str;
    
        HANDLE hFile = CreateFile(fNam,
            GENERIC_WRITE,
            0,
            NULL,
            CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL, NULL);
        DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
        //Offset to where the actual bitmap bits start.
        bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);
        bmfHeader.bfSize = dwSizeofDIB;
        bmfHeader.bfType = 0x4D42; //BM 
    
        DWORD dwBytesWritten = 0;
        WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
        WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
        WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL);
    
        //Unlock and Free the DIB from the heap
        GlobalUnlock(hDIB);    
        GlobalFree(hDIB);
    
        //Close the handle for the file that was created
        CloseHandle(hFile);
    
        //Clean up done:
        //DeleteObject(hBmp);
        return TRUE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an image loader (DevIL) for image loading. Im just wondering if the
I need to compile my Qt application for Windows while I am using Fedora
I am using DevIL in my vc++ application. When build the application I get
As the title suggests, I am trying to load an image using DevIL, before
I have the basic hello world application setup using wai, and would like to
I'm using NetBeans and GlassFish 3.0.1 to create an EJB3 application. I have written
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.