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 6953237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:27:12+00:00 2026-05-27T14:27:12+00:00

I am writing a signature capture control in C++ for Windows Mobile and Windows.

  • 0

I am writing a signature capture control in C++ for Windows Mobile and Windows. On the Windows side I have many different ways to save a CBitmap to a PNG file (GDI+, CImage, etc.). The problem I’ve encountered is CImage::Save() isn’t implemented on Windows Mobile. The good parts of GDI+ are also not implemented on Windows Mobile (specifically, Gdiplus::Bitmap).

I’ve found the IImagingFactory API and had success loading a PNG with this library, but I cannot figure out how to save a CBitmap to a PNG file on Windows Mobile. Does anyone have any ideas to save a HBITMAP or CBitmap to a PNG file?

If it makes any difference, the CBitmap was created to match the size of the control and it has 1BPP since the signature image is black and white and needs to be transferred over the network.

  • 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-27T14:27:12+00:00Added an answer on May 27, 2026 at 2:27 pm

    I’ve learned IImagingFactory encoder was failing because my CBitmap is a DDB rather than DIB. I used CreateDIBSection to create the bitmap instead of CBitmap.Create() and was able to encode the CBitmap to PNG using IImagingFactory.

    Hope this helps the next person who goes down this path (only tested with 1BPP):

    HRESULT CSignatureControl::Imaging_GetCLSID(IImagingFactory *pFactory, LPCTSTR mimeType, CLSID *clsid)
    {
        if (pFactory == NULL)
            return E_INVALIDARG;
        if (mimeType == NULL || mimeType[0] == 0)
            return E_INVALIDARG;
        if (clsid == NULL)
            return E_INVALIDARG;
    
        UINT count = 0;
        ImageCodecInfo *pCodecInfo = NULL;
        HRESULT hr = pFactory->GetInstalledEncoders(&count, &pCodecInfo);
        if (SUCCEEDED(hr))
        {
            for (UINT i = 0; i < count; i++)
            {
                if (!_tcscmp(pCodecInfo[i].MimeType, mimeType))
                {
                    *clsid = pCodecInfo[i].Clsid;
                    break;
                }
            }
            CoTaskMemFree(pCodecInfo);
        }
        return hr;
    }
    
    HRESULT CSignatureControl::Imaging_IBitmapImageFromHBITMAP(IImagingFactory *pFactory, BitmapData *bmData, HBITMAP hBitmap, IBitmapImage **pBitmapImage)
    {
        if (pFactory == NULL)
            return E_INVALIDARG;
        if (hBitmap == NULL)
            return E_INVALIDARG;
    
        BITMAP bm;
        GetObject(hBitmap, sizeof(BITMAP), &bm);
    
        // Map between different pixel formats
        PixelFormatID pixelFormat;
        if (bm.bmBitsPixel == 1)
            pixelFormat = PixelFormat1bppIndexed;
        else if (bm.bmBitsPixel == 4)
            pixelFormat = PixelFormat4bppIndexed;
        else if (bm.bmBitsPixel == 8)
            pixelFormat = PixelFormat8bppIndexed;
        else if (bm.bmBitsPixel == 24)
            pixelFormat = PixelFormat24bppRGB;
    
        bmData->Height = bm.bmHeight;
        bmData->Width = bm.bmWidth;
        bmData->Scan0 = bm.bmBits;
        bmData->PixelFormat = pixelFormat;
        bmData->Stride = ((bm.bmWidth * bm.bmBitsPixel + 31) & ~31) >> 3;
    
        return pFactory->CreateBitmapFromBuffer(bmData, pBitmapImage);
    }
    
    HRESULT CSignatureControl::Imaging_EncodeBitmapToFile(IImagingFactory *pFactory, IBitmapImage *pBitmap, CLSID *clsid, LPCTSTR filename)
    {
        if (pFactory == NULL)
            return E_INVALIDARG;
    
        CComPtr<IImageEncoder> imageEncoder;
        HRESULT hr = pFactory->CreateImageEncoderToFile(clsid, filename, &imageEncoder);
        if (SUCCEEDED(hr))
        {
            CComPtr<IImageSink> imageSink;
            hr = imageEncoder->GetEncodeSink(&imageSink);
            if (SUCCEEDED(hr))
            {
                CComPtr<IImage> pImage;
                hr = pBitmap->QueryInterface(IID_IImage, (void**)&pImage);
                if (SUCCEEDED(hr))
                {
                    hr = pImage->PushIntoSink(imageSink);
                }
            }
            hr = imageEncoder->TerminateEncoder();
        }
        return hr;
    }
    

    Tying it all together:

    CoInitializeEx(NULL, COINIT_MULTITHREADED);
    {
        CComPtr<IImagingFactory> pImgFactory;
        HRESULT hr = pImgFactory.CoCreateInstance(CLSID_ImagingFactory);
        if (SUCCEEDED(hr))
        {
            CLSID pngClsid = {0};
            hr = Imaging_GetCLSID(pImgFactory.p, TEXT("image/png"), &pngClsid);
            if (SUCCEEDED(hr))
            {
                CComPtr<IBitmapImage> pBitmapImg;
                BitmapData *bmData = new BitmapData();
                hr = Imaging_IBitmapImageFromHBITMAP(pImgFactory.p, bmData, m_offscreenBitmap, &pBitmapImg);
                if (SUCCEEDED(hr))
                {
                    hr = Imaging_EncodeBitmapToFile(pImgFactory.p, pBitmapImg, &pngClsid, fileName);
                }
                delete bmData;
            }
        }
    }
    CoUninitialize();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an app that needs to capture a users signature in a
I am writing a program in Monodroid to capture a signature on screen, then
I am writing a shell script to automatically generate an Apple Passbook signature file
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
I am writing a method whose signature is bool isValidString(std::string value) Inside this method
I have a method with the signature public void setFoo(int newFoo) in a model
I am writing C extensions, and I'd like to make the signature of my
I've read about new keyword in method signature and have seen the example below
I'm writing JUnit test code for an android service implementation, and I have to

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.