How Convert Bmp To Icon in VBNET?
Convert Bitmap picture and any image to icon with this sample application. Converting image becomes very simple. If you need to save the icon file, you just need to program and modify the sample code.
I made the sample code using Microsoft Visual Basic 2010.
Imports System.Security.Permissions ' for SecurityPermissionAttribute ''' <summary> ''' Author : Check-Kay Wong ''' ''' Description: Simple application to Convert a BITMAP to ICON in VBNET ''' ''' Anwser a question from : http://www.dreamincode.net/forums/topic/323139-how-convert-bmp-to-icon/ ''' reference to : http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.gethicon(v=vs.100).aspx ''' </summary> ''' <remarks></remarks> Public Class Form1 'Declaration <SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.UnmanagedCode)> _ Public Function GetHicon() As IntPtr End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim oOpenFileDialog As OpenFileDialog Dim oSaveFileDialog As SaveFileDialog Dim oBitmap As Bitmap Dim HIcon As IntPtr Dim newIcon As Icon Dim oFileStream As IO.FileStream oOpenFileDialog = New OpenFileDialog oOpenFileDialog.Filter = "Bitmap File| *.bmp" If oOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = oOpenFileDialog.FileName ' Create a Bitmap object from an image file. oBitmap = New Bitmap(oOpenFileDialog.FileName) ' Get an Hicon for myBitmap. HIcon = oBitmap.GetHicon() ' Create a new icon from the handle. newIcon = System.Drawing.Icon.FromHandle(HIcon) ' Set the form Icon attribute to the new icon. Me.Icon = newIcon 'Save the bitmap to new file oSaveFileDialog = New SaveFileDialog oSaveFileDialog.DefaultExt = ".ico" 'oSaveFileDialog.AddExtension = True If oSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then oFileStream = New IO.FileStream(oSaveFileDialog.FileName, IO.FileMode.CreateNew) newIcon.Save(oFileStream) oFileStream.Close() End If End If End Sub End Class |
Download the sample code here : SampleBitmaptoIcon.zip
Reference :
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :