Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Fuzzy Icons

Fuzzy Icons

Scheduled Pinned Locked Moved C#
question
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Richard Andrew x64R Richard Andrew x64

    For some reason when I display icons in the ListView control, they are slightly fuzzy, or blurred. I'm taking the icons from executable files and displaying them next to the filename, like Windows File Explorer. But in Windows File Explorer, the icons are crystal clear. I have the color depth of the ListView image list set to 32 bits. Anyone have an idea?

    The difficult we do right away... ...the impossible takes slightly longer.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    I assume this is related to your other question in the C/C++ forum. Are you sure you are extracting the correct icon, i.e. having the size that matches the ImageList properties?

    Richard Andrew x64R 1 Reply Last reply
    0
    • L Lost User

      I assume this is related to your other question in the C/C++ forum. Are you sure you are extracting the correct icon, i.e. having the size that matches the ImageList properties?

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #7

      I create the Icon object using the FromHandle method passing in the HICON of the extracted icon. And when I check the size of the new Icon object, it reads 32 x 32, which is the same as the size I set for the ImageList. Maybe the ListView is just bad at displaying icons?

      The difficult we do right away... ...the impossible takes slightly longer.

      L 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        I create the Icon object using the FromHandle method passing in the HICON of the extracted icon. And when I check the size of the new Icon object, it reads 32 x 32, which is the same as the size I set for the ImageList. Maybe the ListView is just bad at displaying icons?

        The difficult we do right away... ...the impossible takes slightly longer.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #8

        Richard Andrew x64 wrote:

        Maybe the ListView is just bad at displaying icons?

        Looking at Image Class (System.Drawing) | Microsoft Docs[^] it gives the impression that only Bitmaps and Metafiles should be used. Icons are rather unique, and may not fit well. You could try using Icon.ToBitmap Method (System.Drawing) | Microsoft Docs[^].

        Richard Andrew x64R 1 Reply Last reply
        0
        • L Lost User

          Richard Andrew x64 wrote:

          Maybe the ListView is just bad at displaying icons?

          Looking at Image Class (System.Drawing) | Microsoft Docs[^] it gives the impression that only Bitmaps and Metafiles should be used. Icons are rather unique, and may not fit well. You could try using Icon.ToBitmap Method (System.Drawing) | Microsoft Docs[^].

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #9

          Great idea! I'll try that. Thanks Richard.

          The difficult we do right away... ...the impossible takes slightly longer.

          1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            For some reason when I display icons in the ListView control, they are slightly fuzzy, or blurred. I'm taking the icons from executable files and displaying them next to the filename, like Windows File Explorer. But in Windows File Explorer, the icons are crystal clear. I have the color depth of the ListView image list set to 32 bits. Anyone have an idea?

            The difficult we do right away... ...the impossible takes slightly longer.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #10

            Didn't think it would be necessary to ask: WPF, Windows Forms or UWP?

            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

            Richard Andrew x64R 1 Reply Last reply
            0
            • L Lost User

              Didn't think it would be necessary to ask: WPF, Windows Forms or UWP?

              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #11

              Windows Forms. I tried Richard's suggestion of converting the icon to a bitmap before adding it to the ImageList, but that didn't fix the fuzziness.

              The difficult we do right away... ...the impossible takes slightly longer.

              L 1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                Windows Forms. I tried Richard's suggestion of converting the icon to a bitmap before adding it to the ImageList, but that didn't fix the fuzziness.

                The difficult we do right away... ...the impossible takes slightly longer.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #12

                This sounds interesting:

                Quote:

                Set the appropriate property—SmallImageList, LargeImageList, or StateImageList—to the existing ImageList component you wish to use.

                [Display Icons for ListView Control - Windows Forms .NET Framework | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-display-icons-for-the-windows-forms-listview-control?view=netframeworkdesktop-4.8)

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                Richard Andrew x64R 1 Reply Last reply
                0
                • L Lost User

                  This sounds interesting:

                  Quote:

                  Set the appropriate property—SmallImageList, LargeImageList, or StateImageList—to the existing ImageList component you wish to use.

                  [Display Icons for ListView Control - Windows Forms .NET Framework | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-display-icons-for-the-windows-forms-listview-control?view=netframeworkdesktop-4.8)

                  It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                  Richard Andrew x64R Offline
                  Richard Andrew x64R Offline
                  Richard Andrew x64
                  wrote on last edited by
                  #13

                  I don't see anything on that page that makes any difference. Thanks for your taking the time to respond.

                  The difficult we do right away... ...the impossible takes slightly longer.

                  1 Reply Last reply
                  0
                  • Richard Andrew x64R Richard Andrew x64

                    For some reason when I display icons in the ListView control, they are slightly fuzzy, or blurred. I'm taking the icons from executable files and displaying them next to the filename, like Windows File Explorer. But in Windows File Explorer, the icons are crystal clear. I have the color depth of the ListView image list set to 32 bits. Anyone have an idea?

                    The difficult we do right away... ...the impossible takes slightly longer.

                    M Offline
                    M Offline
                    mo1492
                    wrote on last edited by
                    #14

                    Without seeing any code I don't know if this will help. I fixed this problem in VB by converting the icon to a bitmap with the routine below. I also use ExtractIconEx. I found that icon.ToBitmap() loses resolution for some reason. Sorry, you'll have to convert to C#. ''' ''' Convert Icon to Bitmap with resizing. ''' ''' ''' ''' ''' Public Shared Function IconToBitmap(ByVal ic As Icon, ByVal sz As Size) As Bitmap If ic Is Nothing Then Return Nothing Dim sourceWidth As Integer = ic.Width Dim sourceHeight As Integer = ic.Height Dim dPercent As Double = 0 Dim dPercentW As Double = 0 Dim dPercentH As Double = 0 dPercentW = (sz.Width / sourceWidth) dPercentH = (sz.Height / sourceHeight) If (dPercentH < dPercentW) Then dPercent = dPercentH Else dPercent = dPercentW End If Dim destWidth As Integer = (sourceWidth * dPercent) Dim destHeight As Integer = (sourceHeight * dPercent) Dim bm As Bitmap = New Bitmap(destWidth, destHeight, PixelFormat.Format32bppArgb) bm.SetResolution(destWidth, destHeight) Dim g As Graphics = Graphics.FromImage(bm) 'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic ' This gives the best quality g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor g.DrawIcon(ic, New Rectangle(0, 0, destWidth, destHeight)) g.Dispose() Return bm End Function

                    Richard Andrew x64R 1 Reply Last reply
                    0
                    • M mo1492

                      Without seeing any code I don't know if this will help. I fixed this problem in VB by converting the icon to a bitmap with the routine below. I also use ExtractIconEx. I found that icon.ToBitmap() loses resolution for some reason. Sorry, you'll have to convert to C#. ''' ''' Convert Icon to Bitmap with resizing. ''' ''' ''' ''' ''' Public Shared Function IconToBitmap(ByVal ic As Icon, ByVal sz As Size) As Bitmap If ic Is Nothing Then Return Nothing Dim sourceWidth As Integer = ic.Width Dim sourceHeight As Integer = ic.Height Dim dPercent As Double = 0 Dim dPercentW As Double = 0 Dim dPercentH As Double = 0 dPercentW = (sz.Width / sourceWidth) dPercentH = (sz.Height / sourceHeight) If (dPercentH < dPercentW) Then dPercent = dPercentH Else dPercent = dPercentW End If Dim destWidth As Integer = (sourceWidth * dPercent) Dim destHeight As Integer = (sourceHeight * dPercent) Dim bm As Bitmap = New Bitmap(destWidth, destHeight, PixelFormat.Format32bppArgb) bm.SetResolution(destWidth, destHeight) Dim g As Graphics = Graphics.FromImage(bm) 'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic ' This gives the best quality g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor g.DrawIcon(ic, New Rectangle(0, 0, destWidth, destHeight)) g.Dispose() Return bm End Function

                      Richard Andrew x64R Offline
                      Richard Andrew x64R Offline
                      Richard Andrew x64
                      wrote on last edited by
                      #15

                      Wow! Thanks Mr. Bump. I'll give this a try. I am thankful that you have solved this problem.

                      The difficult we do right away... ...the impossible takes slightly longer.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups