473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating Image file background colour problem

Hi guys,

I have a problem when trying to create an image file. Basically my
code takes any file and gets it's system icon using SHGetFileInfo and
then saves the file either by converting it into a bmp and saving to
disk or by saving the icon using a filestream. In both cases saving
the file works fine. However, when I open the newly created file from
explorer I notice something peculiar. The file has a black background.
I would have expected the background to be transparent and I can't
understand why vb.net has given it a black bg. Is there any way to
save the file without having the black bg? Any help would be
appreaciated. Code below.

Waqas

//Declare SHGetFileInfo library
Private Declare Auto Function SHGetFileInfo Lib
"shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As
Int32, _
ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Int32, ByVal uFlags As
Int32) As IntPtr

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)_
Private Structure SHFILEINFO
Public hIcon As Int32
Public iIcon As Int32
Public dwAttributes As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)_
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)_
Public szTypeName As String
End Structure

Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1

//Procedure for getting the icon from the filename
Private Sub getIcon(ByRef location As String)
Dim shinfo As SHFILEINFO
shinfo = New SHFILEINFO()
Dim hImgSmall As IntPtr

hImgSmall = SHGetFileInfo(location, 0, shinfo, Len(shinfo),
SHGFI_ICON Or SHGFI_SMALLICON)

//Get the image icon from the file and then sae it as a bmp
Dim myIcon As System.Drawing.Icon
myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
Dim bm As Bitmap = myIcon.ToBitmap()
bm.Save("C:\typeIcon.bmp",
System.Drawing.Imaging.ImageFormat.Bmp)

//Alternative method for saving image as an icon
'Dim file As IO.FileStream
'file = New FileStream("C:\typeIcon.icoo",
FileMode.OpenOrCreate)
'myIcon.Save(file)
'file.Close()
End Sub

Jul 21 '07 #1
0 1407

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
14
by: Eric Lindsay | last post by:
I've seen a page using display, and especially display table that did some neat things with boxes, but basically it only worked with Mozilla browsers. Fell over fairly badly with Opera and Safari...
5
by: R.A. | last post by:
Hi I have an image 700/50 pixels. I want it to be the footer of the web page. Is there a way to make it streach if the browser view area is larger than 700? What I see today is a blank area...
1
by: Dan V. | last post by:
Does anyone know why the header looks correct in IE 6.0 and not Firefox 1.07? I am trying to have a header that looks good when you expand it wider and smaller. In other words when you shrink...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
10
by: Pulzar | last post by:
Hi there, I want to show a simple image on a web page, and allow the viewer to select and change one of the colours used in the image, and immediately preview the result. I'd like to keep the...
2
by: Haines Brown | last post by:
I have situations in which I define the color attribute for an element that is displayed against a background-image. For example, an incipit: #intro:first-letter { margin: -0.05em 0.2em -0.2em...
31
by: Martin Clark | last post by:
Hello, I am daring to stick my head above the parapet and ask as question. I am working on redesigning a website to use CSS rather than tables for layout. I have come across a problem when trying...
1
by: =?Utf-8?B?U3RldmUgQmFya2Vy?= | last post by:
Hi guys, I’m having an interesting problem with Crystal Reports. Thankfully, it’s simple to explain! I’ve got a report, and have added a picture to it. I configured the picture to use a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.