0

I'm trying to get ARGB pixel buffer from an icon file in Windows without using third-party libraries. Icon is loaded as:

   HANDLE hIcon = ::LoadImageA(
      nullptr,
      path.c_str(),
      IMAGE_ICON,
      ICON_SIZE,
      ICON_SIZE,
      LR_LOADFROMFILE | LR_SHARED);

successfully, I can display it with GDI. Is there a way to grab ARGB buffer (I need it further to feed into a graphics library)?

Ivan G.
  • 5,027
  • 2
  • 37
  • 65
  • 2
    Icons is very old Windows concept, there's not necessarily an underlying ARGB buffer. You can convert it into a bitmap like this https://stackoverflow.com/questions/7375003/how-to-convert-hicon-to-hbitmap-in-vc or get information using GetIconInfo : https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-geticoninfo you can also read directly from file format which is documented https://en.wikipedia.org/wiki/ICO_(file_format) but again, there won't necessarily be an ARGB buffer readily available – Simon Mourier Dec 20 '21 at 09:04
  • Thanks for the hint for converting to HBITMAP, I think there is a way to get DIB section afterwards, I'll try. – Ivan G. Dec 20 '21 at 10:46
  • 1
    Unless you don't care about the alpha channel, that's probably not sufficient. If you do care about the alpha channel, you'd have to use the mask for ["regular" icons](https://devblogs.microsoft.com/oldnewthing/20101019-00/?p=12503), identify [true ARGB icons](https://devblogs.microsoft.com/oldnewthing/20101021-00/?p=12483), and see if you can re-use the code that works for ARGB icons for [PNG icons](https://devblogs.microsoft.com/oldnewthing/20101022-00/?p=12473). – IInspectable Dec 20 '21 at 12:18

0 Answers0