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

  • Home
  • SEARCH
  • 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 558043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:05:25+00:00 2026-05-13T12:05:25+00:00

I was wondering whether it’s possible to validate a required size for an icon

  • 0

I was wondering whether it’s possible to validate a required size for an icon before trying:

Dim myIcon = New Icon(theIcon, requestedSize).

This falls over for negative numbers, so that’s an easy check.

It appears it falls over if the number is less than half of the smallest icon.
I’ve looked at the icon class but can see nothing for extracting the sizes.

ETA:

This is pretty annoying. You can put Int32.MaxValue in and it chooses the largest icon. Why it doesn’t choose the smallest icon, as long as size > 0 I don’t know.
If I can determine the size of the smallest icon, then I can do that myself – with no need to throw an exception.

ETA:

Here’s some VB code for anyone who’s interested:

//Returns an array of IconMetaData which contains, amongst other things, the size of
// each image in the icon.

<Extension()> _
Public Function GetMetaData(ByVal icon As Icon) As IconMetaData()
    Using s As New System.IO.MemoryStream
        icon.Save(s)
        Using r As New BinaryReader(s)
            s.Position = 0
            Dim Header As New IconHeader(r)
            Dim Data As New List(Of IconMetaData)
            For i As Integer = 0 To Header.NumberOfIcons - 1
                Dim d As New IconMetaData(r)
                *See note below. 
                If d.Height <> 0 AndAlso d.Width <> 0 Then
                    Data.Add(d)
                End If
            Next
            Return Data.ToArray
        End Using
    End Using
End Function

Private Class IconHeader

    Public ReadOnly NumberOfIcons As Short

    Public Sub New(ByVal r As BinaryReader)
        r.ReadInt16() //Reserved
        r.ReadInt16() //Type, 0=Bitmap, 1=Icon
        Me.NumberOfIcons = r.ReadInt16
    End Sub

End Class

Public Class IconMetaData

    Public ReadOnly Width As Byte
    Public ReadOnly Height As Byte
    Public ReadOnly ColorCount As Byte
    Public ReadOnly Planes As Short
    Public ReadOnly BitCount As Short

    Friend Sub New(ByVal r As BinaryReader)
        Me.Width = r.ReadByte
        Me.Height = r.ReadByte
        Me.ColorCount = r.ReadByte
        r.ReadByte() //Reserved
        Me.Planes = r.ReadInt16
        Me.BitCount = r.ReadInt16
        r.ReadInt32() //Bytes in res
        r.ReadInt32() //Image offset
    End Sub

End Class

*Note: From the couple of icons i’ve tested this with, the first entry has dimensions of (0,0). I don’t know why, and I can’t be sure that all icons have this entry, or that it’s always the first. Therefore, I check each one.

ETA: On further investigation, i’ve found that 0 is used to indicate an icon of size 256.

  • 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-13T12:05:26+00:00Added an answer on May 13, 2026 at 12:05 pm

    You might want to take a look at this article. It looks like it touches on what you are looking for and then some.

    Code Project

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering whether something like this is possible (and relatively easy to do), and
I am new to git. I am wondering whether the following scenario is supported,
I'm fairly new to the STL, so I was wondering whether there are any
I was wondering whether it's possible to override the arrow key functionality that is
I am wondering whether XSLT makes it possible to sort an XML file if
I'm wondering whether it is possible to exclude several source files from a folder
I'm wondering whether anyone here has ever used a skip list . It looks
I've been wondering whether there is a good "git export" solution that creates a
I was wondering whether overriding conversion operators is only applicable to numeric types? If
I was wondering whether the object to test should be a field and thus

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.