Jan 28th, 2005, 04:36 PM
#1
Icon to Bmp [100% Resolved]
How do you convert a icon resource to a valid type for the Image property of a label?
Thanks for any help.
VB Code:
Imports System.IO.Stream
'...
'...
Dim s As System.IO.Stream = Me.GetType.Assembly.GetManifestResourceStream("MyIcon.ico")
Dim bmp As Icon = New Icon(s) 'Crashes here
s.Close()
Me.Label.Image = bmp.ToBitmap
bmp.Dispose()
Last edited by RobDog888; Jan 28th, 2005 at 10:06 PM .
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 04:58 PM
#2
Re: Icon to Bmp
Hi,
If you're getting the error " 'null' is not a valid value for 'stream'.", try this:
VB Code:
Dim s As System.IO.Stream = Me.GetType.Assembly.GetManifestResourceStream( _
Me.GetType.Assembly.FullName.Substring(0, Me.GetType.Assembly.FullName.IndexOf(",")) + ".MyIcon.ico")
Cheers,
NTG
Jan 28th, 2005, 05:05 PM
#3
Re: Icon to Bmp
No dice Its still throwing an exception after your line at this line.
VB Code:
Dim bmp As Icon = New Icon(s)
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 05:08 PM
#4
Re: Icon to Bmp
rob... when you added the icon to the project.. make sure its build action property is set to "embedded resource" and not the default "content"
Jan 28th, 2005, 05:10 PM
#5
Re: Icon to Bmp
Mine works perfectly . I added an .ico file to a project and on build action I selected "Embedded Resource".
If you take a look at the debug window on sStrs(), where that is:
VB Code:
Dim sStrs() As String = Me.GetType.Assembly.GetManifestResourceNames()
do you see your resource in there ?
Cheers,
NTG
Jan 28th, 2005, 05:16 PM
#6
Re: Icon to Bmp
@#$%#, I thought I had set it to embedded when it was added to my project.
I cant believe how much time I wasted on this stupid mistake. Super Doh!
Thanks a ton kleinma. Thanks ntg for your help on this too.
Now a second problem, the image is now being drawn too large. I think it
needs to be 16 x 16 for label images. How do I make it look like it looks when
it is added through the design properties window?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 05:19 PM
#7
Re: Icon to Bmp
I gave you rep points ntg and I tried to give some to kleinma but I need to cover the spread first.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 05:37 PM
#8
Re: Icon to Bmp
Well, you may have an icon with several image types embedded in it. Try either of the following:
1. Open the icon using VS and delete all image types other than 16x16.
2. Create a new image list, add the icon, set the label ImageList property to the image list and set the label ImageIndex to a value according to the number of image types embedded in the icon.
VB Code:
Dim IL As ImageList = New System.Windows.Forms.ImageList
IL.Images.Add(bmp)
Me.Label1.ImageList = IL
Me.Label1.ImageIndex = 2
Cheers,
NTG
Jan 28th, 2005, 05:58 PM
#9
Re: Icon to Bmp
Do I have to use an IL because I want to keep the size small and I heard that
using ILs you suffer loss of quality.
Also, how do I change from one size to the other in order to delete the
unwanted size(s)?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 06:26 PM
#10
Re: Icon to Bmp
Ok, I figured out how to remove the other sizes. Now I am down to one image
in the icon. 16 x 16 - 256 colors. I left the code as is and its working fine now.
Thanks for all the help.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 06:28 PM
#11
Sleep mode
Re: Icon to Bmp
Did you try something like this :
VB Code:
[size=2][color=#0000ff]
Dim[/color][/size][size=2][color=#000000] bmp [/color][/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#000000] Icon = [/color][/size][size=2][color=#0000ff]New[/color][/size][size=2][color=#000000] Icon(s, [/color][/size][size=2][color=#0000ff][b]New[/b][/color][/size][size=2][color=#000000][b] Size(16, 16)[/b])[/color]
[/size]
Jan 28th, 2005, 07:03 PM
#12
Re: Icon to Bmp
No I didn't think of it.
I have it working but my icon has a transparency to it in some areas and I
am getting a black background. How do I fix this?
Thanks.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 07:50 PM
#13
Sleep mode
Originally Posted by
RobDog888
No I didn't think of it.
I have it working but my icon has a transparency to it in some areas and I
am getting a black background. How do I fix this?
Thanks.
I had such problem (alphablended image was drawn half black) . I used used this code to fix it . It simple redraw the picture preserving same color table with different image size if you want . See if this code would help ! You might need to use this function (ConvertToBitmap) that returns Bitmap obj . http://www.vbforums.com/showthread.p...highlight=icon
Jan 28th, 2005, 07:53 PM
#14
Re: Icon to Bmp [99% Resolved]
Yes, I remember reading that thread awhile ago. Thanks, but maybe the code
should be in codebank?
Btw, congradulations on the MCP!
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 07:56 PM
#15
Sleep mode
Re: Icon to Bmp [99% Resolved]
Originally Posted by
RobDog888
Yes, I remember reading that thread awhile ago. Thanks, but maybe the code
should be in codebank?
Btw, congradulations on the MCP!
funny , I'm MCP since 2002 but I just stolen the link from your sig... (You just reminded me).
Yah , I thought pax added it to the codebank .
Jan 28th, 2005, 08:19 PM
#16
Re: Icon to Bmp [99% Resolved]
I'm not able to replicate the issue you're seeing in my tests and I may be missing something, but why bother loading the resource as an Icon only to convert it to a Bitmap (the conversion between formats could be why you're losing the transparency, though I couldn't replicate it.)
The Bitmap class can handle the ICO format, i.e.
VB Code:
Me.Label.Image = New Bitmap(Me.GetType(), "MyIcon.ico")
Jan 28th, 2005, 09:34 PM
#17
Re: Icon to Bmp [99% Resolved]
Dont I have to do something else to tell it to pull from the resource?
I'm still learning.
I attached the icon so you can replicate the issue.
VB Code:
Me.Label1.Image = New Bitmap(Me.GetType(), "2_138.ico")
Attached Files
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 09:48 PM
#18
Re: Icon to Bmp [99% Resolved]
Works fine for me, maybe it has something to do with your container, this is in a UserControl of some sort isn't it?
My tests are with a standard Label with/without a Transparent background on a form.
If you want to email me the project, I'd be happy to look at it for you.
Jan 28th, 2005, 10:05 PM
#19
Re: Icon to Bmp [99% Resolved]
I dont know what was going on but it works now. I just removed
the image that was assigned to the label during design time by way of the
properties window and ran the code you gave me.
Thanks for your help!
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 28th, 2005, 10:12 PM
#20
Sleep mode
Glad you got it working now . It worked good for me also .You should alwalys build the solution (by activating the solution item in the solution explorer and in Build menu , choose Build solution) then run the proj again . This compiles and builds all the files again (including resources) esp. in UC projs . Just my 2cents.
Jan 28th, 2005, 10:18 PM
#21
Re: Icon to Bmp [100% Resolved]
Thanks for the tip and help in both threads. I gave you Reps!
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
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