Need some help in c#

kbirger

Member
Dec 4, 2004
48
0
0
First off, i'm writing a launcher program. It's going to have a context menu with all the apps that the user added (and their respective icons).

Considering that someone might put in 40 apps, that might take a while to cache EVERY icon EVERY time the program starts.

My solution was to add all the icons to an Arraylist and SERIALIZE the arraylist into a .dat file (just plaintext).

Problem: The icon that i add to the arraylist is 256/true-color with alpha transparency. The icon that comes out when i deserialize it is invariably 16 colors with no transparency/regular transparency.

i did some tests, this has nothing to do with the limitations of the icon class. (i displayed the before/after icon for myself). Also, i tested and it has nothing to do with how i'm storing the ArrayList of icons in a .dat file.

does anyone know what is going on or another way i could cache the icons without putting them into separate files?

note: it also seems to have something to do with the way i'm extracting the icon from the exes (SHFileInfo method imported from shell32.dll). If i extract an icon (16x16 16.8 mill color) from an exe and save it on disk, put it in an array, serialize it, unserialize it, check it. it seems to preserve the colors and the transparency, but not the alpha.
 
D

Deleted member 139972

Make sure you're extracting the same number of bits from the file as what you're displaying..
 

kbirger

Member
Dec 4, 2004
48
0
0
the thing is i'm not doing any manual bit work.

i make a call that extracts the icon from the exe (i thoroughly tested this, it extracts the proper icon 100% perfectly)

i make another call that serializes the whole arraylist of icons into a stream and saves the stream to a file.

and a third call that reads the whole file into a stream, deserializing it
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Assuming this is the 1.1 framework, are you calling Application.EnableVisualStyles() and Application.DoEvents() before Application.Run()?

There are several issues related to .NET and losing the alpha channel. Check the FAQ's here and see if any of those situations apply to you.

In particular, it's only the ImageList.Draw() method that can draw transparency. You should probably be adding your icons to an ImageList rather than an ArrayList and then using the ocrresponding Draw() method.
 

kbirger

Member
Dec 4, 2004
48
0
0
the thing is... if i use the icon that i havn't serialized yet, it works fine with the alpha and colors. (so it's not that some setting is preventing alpha from being disabled). and it's not just the alpha that's screwed up. the icon appears in 16 colors.

unless i'm not really understanding what you meant



2.17 Why does adding images to an ImageList in the designer cause them to lose their alpha channel?


Looks like the ImageList editor loses the transparency when it does some internal copy/clone of the images. However, it seems that it does work when you add the images in code to the ImageList.

One workaround (not so tidy) is to add the images to the ImageList in the design time (so that your design-time will be closer to the runtime) and then clear that ImageList and refill it with the images again, in code.

Take a look at this faq on how to add images to your project and retrive them programatically during runtime. Adding image files to a project as an embedded resource and retrieving them programatically.

i tried adding the icon after i deserialize it to an imagelist (didn't help)
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
I just did a quick little test, and this seems to be working for me. I serialized the icon as a png. Perhaps you are serializing as an icon. I don't believe .ico image formats support alpha transparency but png format definitely does.

This is just a little snippet. Obviously there are pieces missing, but pictureBox1 and pictureBox2 end up displaying exactly the same thing when I serialize as a png but NOT when I serialize as an icon.

Hope this helps.
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
And in case anyone was interested in the code I used to extract the icon from the exe, here it is
 

kbirger

Member
Dec 4, 2004
48
0
0
what's the Shell.GetFileIcon() method? because the methodi use to get the icon only gives me a handle for the icon ,then i have to get the icon from the handle...



API.SHGetFileInfoA(sFile, 0, ref SFInfo, Marshal.SizeOf(SFInfo), SHGFI.Icon |SHGFI.SmallIcon);
Icon ico = System.Drawing.Icon.FromHandle(SFInfo.hIcon);
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Originally posted by: kbirger
what's the Shell.GetFileIcon() method? because the methodi use to get the icon only gives me a handle for the icon ,then i have to get the icon from the handle...



API.SHGetFileInfoA(sFile, 0, ref SFInfo, Marshal.SizeOf(SFInfo), SHGFI.Icon |SHGFI.SmallIcon);
Icon ico = System.Drawing.Icon.FromHandle(SFInfo.hIcon);

see my second post. I posted the Shell class I'm using.

 

kbirger

Member
Dec 4, 2004
48
0
0
heh, i'm sorry. i opened the thread, then left the room... then i read it... then i replied... missed the refresh..


but this should work if i make it add the image to an arraylist and serialize it?
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Originally posted by: kbirger
heh, i'm sorry. i opened the thread, then left the room... then i read it... then i replied... missed the refresh..


but this should work if i make it add the image to an arraylist and serialize it?

It worked for me.

 

kbirger

Member
Dec 4, 2004
48
0
0
Thanks a lot for your help. i made some progress...
The alpha still doesn't work correctly, butthe colors do.

i used all your code except i had to separate the serialize and deserialize parts. the images come out as 16 color by default, alphablending doesn't work either way (although binary transparency works) and for some reason if i set the color depth to 32 (like in the pic above) the transparency gets a little weird.
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
Hmm.... you're right. I guess the icons I tested with didn't have a good alpha channel. Try this guy's code and see how that works. The only change I would make is that in framework v 1.1 you don't need a manifest file. Just call Application.EnableVisualStyles() and Application.DoEvents() before Application.Run().
 

kbirger

Member
Dec 4, 2004
48
0
0
sounds good i guess... looks like i have to try to avoid converting them to bitmaps though...

yeah, that just made me certain taht it's impossible to serialize the icons and maintain the alpha layer.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |