|
-
Apr 19th, 2005, 04:51 AM
#1
Thread Starter
Junior Member
Creating icons
Does anyone know how to save a graphic as an icon file so I can use it as an icon in vb6?
Thanks
-
Apr 19th, 2005, 04:56 AM
#2
Re: Creating icons
There are a lot of of icon editor software programs and GIF programs that also save icons. Do a google and you should find a few.
-
Apr 19th, 2005, 05:30 AM
#3
Re: Creating icons
Well there is one easy way of doing it. However it can only create one icon size in the ico resourse, like one 32x32 pixel icon, and only with 16 colors. If that's OK then add a picture box with the inner size of 32x32 pixels, the easiest way is to set the AutoSize property to True and load a 32x32 pixel icon inside it. Then remove that icon. You now have a picture box of the correct size. Now also add an ImageList control to the Form and a CommandButton and the Common Dialog Control. Right click the ImageList control and select Properties. Set the size to 32 x 32.
I'm going to assume you use the origional names for all of these controls. Now in the Command1_Click event use this code:
VB Code:
Private Sub Command1_Click()
Dim pic As StdPicture
Picture1.AutoSize = False
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
Picture1.BackColor = vbRed
Picture1.Cls
Picture1.Picture = LoadPicture()
On Error Resume Next
With CommonDialog1
.CancelError = True
.Filter = "Bitmaps|*.bmp"
.DefaultExt = "bmp"
.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
.DialogTitle = "Pick a small bitmap (size 32x32)"
.ShowOpen
If Err.Number = cdlCancel Then
Exit Sub
End If
Set pic = LoadPicture(.FileName)
Picture1.PaintPicture pic, 0, 0, 32, 32, , , , , vbSrcCopy
ImageList1.ListImages.Clear
ImageList1.UseMaskColor = True
ImageList1.MaskColor = vbRed
ImageList1.ListImages.Add Picture:=Picture1.Image
Picture1.Cls
.Filter = "Icons|*.ico"
.DefaultExt = "ico"
.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly + cdlOFNPathMustExist
.DialogTitle = "Save icon"
.ShowSave
If Err.Number = cdlCancel Then
Exit Sub
End If
Picture1.Cls
Picture1.Picture = ImageList1.ListImages(1).ExtractIcon
SavePicture Picture1.Picture, .FileName
End With
MsgBox "Icon saved", vbInformation
End Sub
This code will prompt you to open a small bitmap file that it will convert to an icon. After you have selected a bitmap, it will then prompt you for the name you want to use to save the icon.
So to create an icon you simply create a BMP file in for example MS Paint and load it in this program. You can also use this as a base for a simple Icon Editor.
If you want to a more advanced icon you need to use DIB sections. Do a search on http://www.vbaccelerator.com that has an icon editor control and also several articles on the subject.
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
|