Results 1 to 8 of 8

Thread: code for working with .ico files?

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    code for working with .ico files?

    This may be a toughy, but here goes.

    Does anyone know how to read an .ico file and (1) identify the types of images it contains (i.e. "32X32 256 color", "16X16 256 color", "48X48 etc.") and (2) save off to a new file a file with only the image sizes I want (i.e. just 32x32, or just 32x32 and 16x16, etc.).

    Now - really pushing it - does anyone know how to create a "gray-scale" image, given a color image (i.e. read in a normal color-icon, apply gray scale to it, and output the gray scale "disabled-looking" image)?

    Any help would be appreciated.
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Looks like maybe the CopyImage API would be of some help.
    VB Code:
    1. Declare Function CopyImage Lib "user32" (ByVal handle As Long, ByVal imageType As Long, _
    2. ByVal newWidth As Long, ByVal newHeight As Long, ByVal lFlags As Long) As Long
    3.  
    4. The CopyImage function creates a new image (icon, cursor, or
    5. bitmap) and copies the attributes of the specified image to the
    6. new one. If necessary, the function stretches the bits to fit the
    7. desired size of the new image.
    8.  
    9. · hinst
    10. Identifies an instance of the module that contains the image to be copied.
    11.  
    12. · uType
    13. Specifies the type of image to be copied. This parameter can be one of the following values:
    14. IMAGE_BITMAP
    15.  Copies a bitmap.
    16. IMAGE_CURSOR
    17.  Copies a cursor.
    18. IMAGE_ICON
    19.  Copies an icon.
    20.  
    21. · cxDesired
    22. Specifies the desired width, in pixels, of the image.
    23.  
    24. · cyDesired
    25. Specifies the desired height, in pixels, of the image.
    26.  
    27. · fuFlags
    28. Specifies a combination of the following values:
    29. LR_COPYDELETEORG
    30.  Deletes the original image after creating the copy.
    31. LR_COPYRETURNORG
    32.  Creates an exact copy of the image, ignoring the cxDesired and cyDesired parameters.
    33. LR_MONOCHROME
    34.  Creates a new monochrome image.
    35. LR_COPYFROMRESOURCE
    36.  Tries to reload an icon or cursor resource from the original
    37.  resource file rather than simply copying the current image. This is
    38.  useful for creating a different-sized copy when the resource file
    39.  contains multiple sizes of the resource. Without this flag,
    40.  CopyImage stretches the original image to the new size. If this
    41.  flag is set, CopyImage uses the size in the resource file closest  to
    42.  the desired size.
    43.  
    44. This will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by LoadImage with the LR_SHARED flag.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Also may be useful...
    VB Code:
    1. Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
    2. (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge _
    3. As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
    4.  
    5. · lpszFile
    6. Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file.
    7.  
    8. · nIconIndex
    9. Specifies the index of the icon to retrieve. If this value is 0, the
    10. function returns the handle of the first icon in the specified file. If
    11. this value is -1 and phIconLargeand phiconSmall are both NULL,
    12. the function returns the total number of icons in the specified file.
    13.  
    14. · phiconLarge
    15. Pointer to an array of handles of large icons returned. This parameter can be NULL.
    16.  
    17. · phiconSmall
    18. Pointer to an array of handles of small icons returned. This parameter can be NULL.
    19.  
    20. · nIcons
    21. Specifies the count of the number of icons to extract.
    Edit: This post puts me in the top 40!
    Last edited by RobDog888; Oct 13th, 2004 at 04:36 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Thanks, Rob, I'll take a look at these.
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob. Let me know if it works for you.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    If you're into writing your own algorithems and such:
    http://www.wotsit.org/search.asp?page=2&s=windows

    Disiance

  7. #7
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    Hey BruceG, there is a Icon Editor Control on www.vbaccelerator.com which does everything u want and with less efforts.

  8. #8

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Wow - good tip, Deepak, thank you.
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width