Icon Ripper
Post your questions regarding programming in Visual Basic 6 in here.
Hey I recently Decided to create an application that extracts or "rips" the .ico file from a .exe file. the entire code is here :
Contains:
3 buttons Save, Browse, Rip.
1 Textbox
1 Savefiledialog
1 Openfiledialog
2 Labels
1 Picturebox (32 pixles by 32 pixels, Default Icon size.)
Picture:http://s1003.photobucket.com/albums/af1 ... g&newest=1
Sadly, when I choose a the location to save the icon file to and click save the file isn't there. Vb 2008 doesn't detect any errors so can somebody test this for me and find out the issue with the save-button.
Code: Select all
:shock: Public Class Form1
Private Sub RIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RIP.Click
Dim ricon As Icon = Icon.ExtractAssociatedIcon(TextBox1.Text)
PictureBox1.BackgroundImage = ricon.ToBitmap
End Sub
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
Using ofd As New OpenFileDialog
ofd.Filter = ".exe (*exe*)|*.exe*"
ofd.Title = "Select File"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd.FileName
End If
End Using
End Sub
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
Dim savefiledialog1 As New SaveFileDialog
Try
savefiledialog1.Title = "Save File"
savefiledialog1.FileName = "*.ico"
savefiledialog1.Filter = "Icon |*.ico"
If savefiledialog1.ShowDialog() = DialogResult.OK Then
PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Icon)
End If
Catch ex As Exception
'Do Nothing
End Try
End Sub
End Class
Contains:
3 buttons Save, Browse, Rip.
1 Textbox
1 Savefiledialog
1 Openfiledialog
2 Labels
1 Picturebox (32 pixles by 32 pixels, Default Icon size.)
Picture:http://s1003.photobucket.com/albums/af1 ... g&newest=1
Sadly, when I choose a the location to save the icon file to and click save the file isn't there. Vb 2008 doesn't detect any errors so can somebody test this for me and find out the issue with the save-button.
Hello bjm0008,
Nice application your building. Ive never tried to save an image as an *.ico file before using VB so I dont know exactly how its done. Ive done some research and this is the simplest way I could do it, the only issue is that it saves them in 16-colors.
The reason why your application wasnt saving anything was because in the RIP_click sub you set the image to the picturebox's background, you need to set it to Picturebox1.Image instead.
Here is the code I came up with and I hope it helps you in some way:
Nice application your building. Ive never tried to save an image as an *.ico file before using VB so I dont know exactly how its done. Ive done some research and this is the simplest way I could do it, the only issue is that it saves them in 16-colors.
The reason why your application wasnt saving anything was because in the RIP_click sub you set the image to the picturebox's background, you need to set it to Picturebox1.Image instead.
Here is the code I came up with and I hope it helps you in some way:
Code: Select all
Good luck! Imports System.drawing
Imports System.IO
Public Class Form1
Private Sub RIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RIP.Click
Dim ricon As Icon = Drawing.Icon.ExtractAssociatedIcon(TextBox1.Text)
PictureBox1.Image = ricon.ToBitmap
End Sub
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
Using ofd As New OpenFileDialog
ofd.Filter = ".exe (*exe*)|*.exe*"
ofd.Title = "Select File"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd.FileName
End If
End Using
End Sub
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
Try
SaveFileDialog1.Title = "Save File"
SaveFileDialog1.FileName = "*.ico"
SaveFileDialog1.Filter = "Icon |*.ico"
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
Dim Newico As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim ico As Graphics = Graphics.FromImage(Newico)
ico.DrawImage(PictureBox1.Image, 0, 0, PictureBox1.Width, PictureBox1.Height)
Dim SaveIcon As Icon = System.Drawing.Icon.ExtractAssociatedIcon(TextBox1.Text)
SaveIcon.Save(New FileStream(SaveFileDialog1.FileName, FileMode.Create))
End If
Catch ex As Exception
MsgBox("Error while saving!")
End Try
End Sub
End Class
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Thanks for the reply I tried the code and it works perfectly, well exept for the colors. I'm not so good with them anyways. Just post a reply if you get any more ideas.
This was kinda fast but I think I've got it!
( I canched the browse butto so it automaticly puts the icon into the picturebox )
There is just one problem Visual Studio or even windows won't accept the .ico file.
If i named the .ico as icon1.ico it'll say "icon1.ico does not contain any icon files"
( I canched the browse butto so it automaticly puts the icon into the picturebox )
Code: Select all
Imports System.Drawing.Color
Imports System.Drawing
Imports System.IO
Public Class Form1
Private Sub RIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RIP.Click
Dim ricon As Icon = Drawing.Icon.ExtractAssociatedIcon(TextBox1.Text)
PictureBox1.Image = ricon.ToBitmap
End Sub
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
Using ofd As New OpenFileDialog
ofd.Filter = ".exe (*exe*)|*.exe*"
ofd.Title = "Select File"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd.FileName
End If
End Using
End Sub
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
Dim savedialog1 As New SaveFileDialog
SaveFileDialog1.Filter = "Icon File (*.ico|*.ico |All Files | *.*"
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Icon)
End If
End Sub
End Class
There is just one problem Visual Studio or even windows won't accept the .ico file.
If i named the .ico as icon1.ico it'll say "icon1.ico does not contain any icon files"
Hello,
Your rite the code you have does save the picturebox to an .ico file but for some reason VB doesnt save it with any icon format properties. What it actually does is save it in .png format, if you rename one of your saved icon files to say for example "icon1.png" then you will be able to view it inside an image viewer or VB.
The code I posted above saves the file with .ico format properties but its only 16-colors which isnt very good I know.
I would have thought it was simple to save a file as .ico but I guess its not :?
Your rite the code you have does save the picturebox to an .ico file but for some reason VB doesnt save it with any icon format properties. What it actually does is save it in .png format, if you rename one of your saved icon files to say for example "icon1.png" then you will be able to view it inside an image viewer or VB.
The code I posted above saves the file with .ico format properties but its only 16-colors which isnt very good I know.
I would have thought it was simple to save a file as .ico but I guess its not :?
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Hello again,
I found this somewhere online (before my browser crashed). It lets you open a .BMP file and save it as a .ico file, seems to work pretty well. If you play about with it you should be able to change it so you can extract an icon from an .exe and save it to .ico.
This is the file:
I found this somewhere online (before my browser crashed). It lets you open a .BMP file and save it as a .ico file, seems to work pretty well. If you play about with it you should be able to change it so you can extract an icon from an .exe and save it to .ico.
This is the file:
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
Copyright Information
Copyright © Codenstuff.com 2020 - 2023