Hello.
I want to display a icon in an image control. For this I'm writing code as:
But it says, the picture is invalid.Code:ImgPreview.Picture = LoadPicture(CmDialog.FileName, vbLPCustom, , 28, 28)
Printable View
Hello.
I want to display a icon in an image control. For this I'm writing code as:
But it says, the picture is invalid.Code:ImgPreview.Picture = LoadPicture(CmDialog.FileName, vbLPCustom, , 28, 28)
Have you tried supplying the color depth?
Also, is the icon 32 bit?
What if icon is not 32-bit??
I supplied color dept as VbLPDefualt. It still says, Invalid Picture.
Can you upload the icon?
Actually, the icon is not fixed. The user selects icon at the runtime and I want to show its preview under image control. The icons source may be (*.ico, *.exe and *.dll).
LoadPicture doesn't work with EXE or DLL files as the source.
So, what can I do to make the preview of those icon files under an image control??
Research the PE structure. :)
I didn't get it. What does PE means??Quote:
Research the PE structure.
Hello, look this user control, can help.
http://www.leandroascierto.com.ar/ca...lphaIcon32.php
Portable executable.
It's the file format for a Windows executable.
It includes the resource fork(like if you add resource files to your EXE), which includes an ICON fork.
Typically they're stored unobfuscated.
More here: http://www.wotsit.org/list.asp?al=E
@LeandroA:
Well, I didn't understand the language used in the site. I downloaded it. But what must be me doing with it? I didn't get any clues. Also, I can't upload icons.
@FireXtol:
I guess, that doesn't help me.
Time to use your friends (yahoo, google, ask, answers bing) and search for vb6 extracticonex. When you retrieve your results, make sure you check out both thescarms and vbaccelerator 's example programs...
Good Luck
In my signature below (Icon Organizer), you can find code to extract icons from an exe, dll, ocx.
Any 32bpp icon will never load in VB via LoadPicture; you cannot assign a 32bpp icon to any .Picture or .Icon property -- they are not supported.
Then, can it be converted to other supported formats at runtime??Quote:
Any 32bpp icon will never load in VB via LoadPicture; you cannot assign a 32bpp icon to any .Picture or .Icon property -- they are not supported.
Ok. You've managed to load those pictures to your form. Can you write a function to convert the icon to supported image??
Easy to do, but quality will suffer. One can convert 32bpp to 24bpp which is supported. But 32bpp are generally alphablended giving you nice blended shadows for example. Converting to 24bpp means those shadows will no longer be blended, but solid, and will result in poor quality. The real answer is to not convert those icons for .Picture/.Icon properties but to draw them directly on the form/picturebox using the DrawIconEx API and you will get the best quality; but this does require some more code. The Image Control is a convenient tool, but not for modern graphics. Also, 32bpp icons are supported in XP and above only.
Ok, I'm now gonna use picturebox instead of ImageBOx. Can you show me an API declaration and the code to draw icon to picturebox?
Look at the Icon Organizer link in my signature and sample code is in post #1 in that link: Bonus Code #2.
Another answer is to not use 32bpp icons or remove them from the icon file/resource. But if your users can pick any icon, then that may not be so easy as the icon may only consist of 32bpp formats.
I have no idea what you are doing there. Can you simplify it?
Ok, in order to us the DrawIconEx API, you will need an hIcon handle. There are a few ways to get that handle
1) Read the bytes into an array using VB & Binary file mode. Use the sample code I mentioned and create an Icon from the first icon in the file. (example given in that link)
2) Use other APIs like LoadImage (example given in that link)
3) Manually parse the icon file which I don't think you want to do
The only thing not given in that link is an example of DrawIconEx. It is so easy to use.
If you create an icon, you must remember to destroy it at some point else memory leaks can occur.
I guess I'm getting it now. I will try those codes with my projects. If any problem occurs I will be back right here.
Alright. The function DrawIconEx works well. I'm using transparent frame and the area where icon is to be drawn is covered by the same frame. But after drawing, the icon doesn't appear.
Actually, I'm not making the frame transparent. I'd downloaded an transparent frame control (.ocx) and used in my project.
Try refreshing the frame control after drawing.
Or, try hiding and showing that frame control, after drawing.Code:Frame1.Refresh
Example:
...:wave:Code:Frame1.Visible=False
DrawICON
Frame1.Visible=True
This control doesn't support REFRESH method. And about the next idea, it failed. What do I do next??
Can you send me a sample to work out ? Try to include the transparent OCX also. I will experiment it...:wave:
Here is my project.
I have tried it, but it looks like the Transparent Frame control use to paint the background on app loading only. I have tried assigning the transparency property at runtime. But that too doesn't show any effect.
May be you should display the picture somewhere else.
If you want to display the icon in a picturebox, you can try this in DrawIconEx line:
...:wave:Code:DrawIconEx Picture1.hdc, 0, 0, mIcon, 0, 0, 0, 0, DI_NORMAL
Alright. Now I've placed picturebox set its border style to none. It works as I had wanted.
Thanks a lot!!!