By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

make background color transaparent

P: n/a
hi all..
let's suppose that we have a file (word1.doc)
i have managed to extract the icon from the file by using
-------------------
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" (ByVal
pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As
SHFileInfo, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr
-------------------
and keep it in a System.Drawing.Icon variable.
My problem is that there is a black background in the icon which i want to
get rid
of ! I have tried to convert the icon into a bit map using
------------------
Dim bb As Drawing.Bitmap = extractedIcon.ToBitmap()
------------------

and then make the black color transparent using
------------------
bb.MakeTransparent(Color.Black)
------------------

Finally i restore the icon back from the bitmap
-----------------
Dim extractedIcon As System.Drawing.Icon
extractedIcon2 = System.Drawing.Icon.FromHandle(bb.GetHicon)
----------------

Unfortunately the black backcolor remains. Is there a way to get rid of it ?
thx a lot
theodore
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Theodore,

This is what I tried
///
Dim btmap As Bitmap
Dim icn As Icon

Me.pbox.Image = Nothing
icn = New Icon("C:\MSGBOX03.ICO")
btmap = icn.ToBitmap
btmap.MakeTransparent(Color.Yellow)

Dim extractedIcon As System.Drawing.Icon
extractedIcon = icn.FromHandle(btmap.GetHicon)

Me.pbox.CreateGraphics.DrawIcon(extractedIcon, pbox.Width / 4,
pbox.Height / 4)

\\\

This worked meaning, the icon that showed up did have the Yellow color
masked. I am not sure why it did not work for you. Let me know if I missed
anything and I will try to help.
Nov 21 '05 #2

P: n/a
hi sarika
thx for the answer...
this seems to be the same as the one that i am describing...
i will try it again tomorrow...cos now i am not at work..
but i will give u a couple of more info..
1. the code i am writing is on a code behind aspx.vb file...
2. i am extracting the icon from a file... saving it to disk and then
passing it as an imageUrl to a web tree node (infragistics ultrawebtree)
3. when i am using the same code,in a vb project, but istead of saving the
icon - by using the memoryStream- i am adding it to the collection of an
image control... no black background is shown at the first place !! (and
therefore no need for maketransparent method)..
anyway ,thx once more
i will try to accomplish it tomorrow...
if u have any more ideas..plz let me know !:)
theodore

"Sarika" wrote:
Hi Theodore,

This is what I tried
///
Dim btmap As Bitmap
Dim icn As Icon

Me.pbox.Image = Nothing
icn = New Icon("C:\MSGBOX03.ICO")
btmap = icn.ToBitmap
btmap.MakeTransparent(Color.Yellow)

Dim extractedIcon As System.Drawing.Icon
extractedIcon = icn.FromHandle(btmap.GetHicon)

Me.pbox.CreateGraphics.DrawIcon(extractedIcon, pbox.Width / 4,
pbox.Height / 4)

\\\

This worked meaning, the icon that showed up did have the Yellow color
masked. I am not sure why it did not work for you. Let me know if I missed
anything and I will try to help.

Nov 21 '05 #3

P: n/a
"juststarter" <ju*********@discussions.microsoft.com> schrieb:
[Extracting an icon]
Unfortunately the black backcolor remains. Is there a way to get rid of it
?


<URL:http://dotnetrix.co.uk/misc.html>
-> "Get Alpha Bitmap from 32 bit Icon."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
it didnt work herfried :SS
what i do is the following
1. extract the file icon out of a file (residing on the hard disk)
2. feed the function with the icon
3. save the bitmap that the function returns on the disk
4. get an icon from that bitmap
5. save the icon on the disk

unfortuately both the bmp and the ico still have the black background
......

ps: i am not sure that i am feeding the procedure with a 32 bit icon... is
there a way to find out ?
"Herfried K. Wagner [MVP]" wrote:
"juststarter" <ju*********@discussions.microsoft.com> schrieb:
[Extracting an icon]
Unfortunately the black backcolor remains. Is there a way to get rid of it
?


<URL:http://dotnetrix.co.uk/misc.html>
-> "Get Alpha Bitmap from 32 bit Icon."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.