Convert 32x32 icon to 16x16

Hi, finally I had the occasion to contribute in CodeGuru site. Well, this is my humble solution to convert an icon from 32x32 format to 16x16. The procedure is very simple, I get the two bitmaps of the icon (the image bitmap and the mask bitmap) and I resize separately each bitmap from 32x32 to 16x16, with these two new bitmaps obtained from the conversion is possible to make a new 16x16 icon generated by the mother 32x32. Theorically the procedure is correct and it works well enough; however, I noticed that the conversion made by Windows obtains the best result compared with this, if anyone have an idea about to improve this algorithm any suggestion will be welcomed.

HICON Convert32x32IconTo16x16(HICON h32x32Icon)
  HDC hMainDC, hMemDC1, hMemDC2;
  HICON h16x16Icon;
  BITMAP bmp;
  HBITMAP hOldBmp1, hOldBmp2;
  ICONINFO IconInfo32x32, IconInfo16x16;

  GetIconInfo(h32x32Icon, &IconInfo32x32);

  hMainDC = ::GetDC(m_hWnd);
  hMemDC1 = CreateCompatibleDC(hMainDC);
  hMemDC2 = CreateCompatibleDC(hMainDC);

  GetObject(IconInfo32x32.hbmColor, sizeof(BITMAP), &bmp);

  IconInfo16x16.hbmColor = CreateBitmap( 16, 16, 

  hOldBmp1 = (HBITMAP) SelectObject( hMemDC1, 
  hOldBmp2 = (HBITMAP) SelectObject( hMemDC2,

       0, 0,
       16, 16,
       0, 0,
       32, 32,

  GetObject(IconInfo32x32.hbmMask, sizeof(BITMAP), &bmp);

  IconInfo16x16.hbmMask = CreateBitmap( 16, 16, 

  SelectObject(hMemDC1, IconInfo32x32.hbmMask);
  SelectObject(hMemDC2, IconInfo16x16.hbmMask);

             0, 0,
             16, 16,
             0, 0,
             32, 32,

  SelectObject(hMemDC1, hOldBmp1);
  SelectObject(hMemDC2, hOldBmp2);

  IconInfo16x16.fIcon = TRUE;
  h16x16Icon = CreateIconIndirect(&IconInfo16x16);

  ::ReleaseDC(m_hWnd, hMainDC);

  return h16x16Icon;


  • Better results....

    Posted by Legacy on 07/04/2003 12:00am

    Originally posted by: Oskar Wieland

    You just have to call SetStretchBltMode( hMemDC2, HALFTONE ) before doing the StretchBlt.

    All the best

  • Good! but...

    Posted by Legacy on 02/07/2003 12:00am

    Originally posted by: Zhang

    I have a problem.I want to generate a HICON from 2 HICONs. Can you tell me how can I get it?

  • Excellent ! ... How do you save both the 32x32 and the 16x16 into the ICO file

    Posted by Legacy on 01/24/2003 12:00am

    Originally posted by: Aharon Tam

    Very helpfull article.

    I intend to use to convert a 32 x 32 Icon Large Icon
    to a 16 x 16 Small Icon.
    However I wonder how save both icons into the same
    *.ico file under res directory.

    • sdf

      Posted by eran2 on 06/17/2009 02:15am


  • How about CopyImage(...)?

    Posted by Legacy on 01/23/2002 12:00am

    Originally posted by: Robert Moerland

    I use CopyImage from the Win32 API to let Windows do the 32-to-16 scaling. It would be something like:

    HICON 16x16Icon = (HICON) CopyImage(h32x32Icon, IMAGE_ICON, 16, 16, LR_COPYFROMRESOURCE);

    The LR_COPYFROMRESOURCE flag makes sure that if there's a 16x16 icon, it is used instead of scaling a 32x32 icon.

    Robert Moerland

  • Thank you

    Posted by Legacy on 01/18/2002 12:00am

    Originally posted by: Diarrhio

    This helped a lot. Have been trying to figure this one out forever!


  • Better Looking Icons

    Posted by Legacy on 01/17/2002 12:00am

    Originally posted by: Chris Richardson


    You had a question on how to possibly get better looking small icons. Under Windows NT and Windows 2000, you can set the stretching mode of the device context using the function call SetStretchBltMode. If you set the stretch mode to HALFTONE, you will probably get better small icons. You would probably want to add code to test for the version of the OS using GetVersionEx before attempting to set the mode though. Also, the MSDN says the HALFTONE mode is slower. In my own practice, I've noticed that the HALFTONE mode is about 3 times slower, however, with such small images, this difference is negligible.

    Nice work,

    Chris Richardson

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date