|
-
Sep 10th, 2000, 06:03 AM
#1
Thread Starter
Addicted Member
How come when I extract an icon to a picture box and use the SavePicture method, the back ground of the file.ico is black and the image is smaller?
Picture box be transparent?
-
Sep 10th, 2000, 07:11 AM
#2
You extract an icon from a file and paint it to a picturebox and then you save the bitmap by using SavePicture, right?
What you save is a BMP file and not the icon.
If you want to convert the bitmap you have painted on the picture box back to an icon then do the following:[*]Add an ImageList control to the Form[*]Set the MaskColor of the ImageList to the same as the BackColor of the PictureBox[*]When you have drawn the icon on the PictureBox add the image to the ImageList ListImages collection.[*]Clear the PictureBox[*]Use the ExtractIcon method of the ImageList ListImages collection to pull the image back from the ImageList to the PictureBox[*]Now you have an icon in the PictureBox save it with the SavePicture function
Code:
ImageList1.ListImages.Add , "Icon", Picture1.Image
Picture1.Cls
Picture1 = ImageList1.ListImages("Icon").ExtractIcon
ImageList1.ListImages.Clear
SavePicture Picture1, "c:\MyIcon.ico"
Good luck!
-
Sep 10th, 2000, 03:14 PM
#3
Thread Starter
Addicted Member
The background is still black. The picture lost its size and became distorted too.
-
Sep 10th, 2000, 05:06 PM
#4
How do you extract the icon and how are you painting it to the picture box?
-
Sep 10th, 2000, 05:39 PM
#5
Thread Starter
Addicted Member
I got this somewhere on this site.
Code:
Option Explicit
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Sub Form_Load()
'Set initial settings
Picture1.AutoRedraw = True
Me.ScaleMode = vbPixels
End Sub
Private Sub Command1_Click()
Dim hIcon As Long
'Extract the icon from Calculator
hIcon = ExtractIcon(App.hInstance, "C:\myproject.exe", 0)
'Draw the Icon on to Picture1
DrawIcon Picture1.hdc, 0, 0, hIcon
Picture1.Picture = Picture1.Image
'Convert the Bitmap to an Icon
ImageList1.ListImages.Add , , Picture1.Picture
Picture1.Cls
Set Picture1.Picture = Nothing
Set Picture1.Picture = ImageList1.ListImages(1).ExtractIcon
'Save the Icon
SavePicture Picture1.Picture, App.Path & "\MyIco.ico"
End Sub
Thanks Joacim for always helping.
-
Sep 10th, 2000, 05:59 PM
#6
Make sure the picture box is 32x32 pixels in size (or 36x36 if it has a border).
-
Sep 10th, 2000, 06:35 PM
#7
Thread Starter
Addicted Member
That did the trick for some icons. There are others that are smaller so I have to change the imagelist size.
Thanks.
I think I have to play around with the size in the imagelist.
-
Sep 10th, 2000, 06:40 PM
#8
Well, ExtractIcon always extracts the 32x32 icon.
If you want to extract icons in the size of 16x16 use ExtractIconEx instead.
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
|