|
-
Aug 23rd, 2012, 12:28 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Rescale Favicon On The Fly
Hi,
I'm grabbing a favicon from a website and add it to a tab.
Does anyone know how to scale it? Some of the favicons are larger then 16*16, which makes it a big image on the tab.
My code to grab it:
vb.net Code:
For Each element As Gecko.GeckoElement In xGecko.Document.DocumentElement.GetElementsByTagName("link")
If element.GetAttribute("rel").ToLower = "shortcut icon" Then
result = element.GetAttribute("href")
Exit For
End If
Next
Try
Dim WebClient As New WebClient
Dim MS As New MemoryStream(WebClient.DownloadData(result))
Dim favicon As New Icon(MS)
web_tab.SelectedTab.Icon = favicon
-
Aug 24th, 2012, 04:53 AM
#2
Re: Rescale Favicon On The Fly
 Originally Posted by Radjesh Klauke
Does anyone know how to scale it? Some of the favicons are larger then 16*16, which makes it a big image on the tab.
Maybe draw the icon as a bitmap in the new size then convert it back to an icon?
vb.net Code:
<System.Runtime.InteropServices.DllImportAttribute("user32.dll")> _ Private Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean End Function Private Function ResizeIcon(ByVal icon As Icon, ByVal width As Integer, ByVal height As Integer) As Icon Using bmp As New Bitmap(width, height) Using g As Graphics = Graphics.FromImage(bmp) g.Clear(Color.Transparent) g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.DrawIcon(icon, New Rectangle(0, 0, width, height)) ' draw icon in new size Dim ico As Icon = icon.FromHandle(bmp.GetHicon) Dim resizedIcon As Icon = New Icon(ico, ico.Size) DestroyIcon(ico.Handle) ' avoid GDI memory leak Return resizedIcon End Using End Using End Function ' ~~~~~~~ if favicon.size <> new size(16,16) then Dim newIcon As Icon = ResizeIcon(favicon, 16,16) web_tab.SelectedTab.Icon = newIcon newIcon.dispose() else web_tab.SelectedTab.Icon = favicon end if favicon.dispose()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|