Dot-Net
使用 Icon.ExtractAssociatedIcon 和 ImageList 獲得完整質量的 16 x 16 圖示
按照這個問題的指示,我執行了一些程式碼來從文件中提取圖示並在設置為詳細資訊模式的 ListView 中顯示它們。我希望圖示以 16 x 16 顯示,但是當我將 ImageList 大小設置為該圖示時,出現的圖示看起來很奇怪(不知道如何描述它 - 請參閱隨附的螢幕截圖)。
我已經嘗試將大小更改為 32 x 32 並且效果很好,但肯定有辦法獲得高質量的 16 x 16 圖示,不是嗎?
http://img165.imageshack.us/img165/4446/badqualityiconscc4.png
您必須使用 2 個圖像列表,一個用於小圖像,一個用於大圖像,以獲得我認為的最佳結果。(listview有兩個屬性,LargeImageList和SmallImageList)
編輯(發現我嘗試時有效的新資訊):
這個版本是使用插值來獲得更小的拇指,應該會更好。
Dim BigIcon As Icon = Nothing BigIcon = Icon.ExtractAssociatedIcon("c:\zebra.zip") Dim largeimages As New ImageList Dim smallimages As New ImageList largeimages.Images.Add("1", BigIcon) 'Fix a smaller version with interpolation Dim bm As New Bitmap(BigIcon.ToBitmap) Dim thumb As New Bitmap(16, 16) Dim g As Graphics = Graphics.FromImage(thumb) g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.DrawImage(bm, New Rectangle(0, 0, 16, 16), New Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel) g.Dispose() bm.Dispose() smallimages.Images.Add("1", thumb) ListView1.SmallImageList = smallimages ListView1.LargeImageList = largeimages thumb.Dispose() ListView1.Items.Add("Test", "Test", "1")