Fuzzy Icons
-
Richard Andrew x64 wrote:
Does the ListView control offer the capability to display the same icon(s) at different sizes?
Beyond my pay grade, I'm sorry. Ask an expert. ;P
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
All I can do is ask everybody and hope an expert answers. ;)
The difficult we do right away... ...the impossible takes slightly longer.
-
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.
-
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?
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.
-
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.
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 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[^].
Great idea! I'll try that. Thanks Richard.
The difficult we do right away... ...the impossible takes slightly longer.
-
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.
-
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
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.