473,390 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Problem reading small icon from database (repeat post PLEASE HELP)

I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them back when I open the form.

Here's the problem: the large icons load fine but the small ones give
an error stating "Invalid Parameter Used". Below are the two routines
for saving and loading the icons:

Public Function IconToBytes(ByVal icon As Icon) As Byte()
'Converts an Icon object into an array of bytes so
'it can be saved to a database field
Dim loMemoryStream As New IO.MemoryStream
icon.Save(loMemoryStream)
Dim laIcon(loMemoryStream.Length - 1) As Byte
loMemoryStream.Position = 0
loMemoryStream.Read(laIcon, 0, loMemoryStream.Length)
Return laIcon
End Function

Public Function DataFieldToImage(ByVal oField As Object) As Image
'Converts an array of bytes to an Icon object when read
'from a database field.
If Not IsDBNull(oField) Then
Dim laImage() As Byte = oField
Dim loMemoryStream As New IO.MemoryStream(laImage)
Return Image.FromStream(loMemoryStream)
Else
Return Nothing
End If
End Function

I could not figure out how to load directly into an Icon object, so it
is loading into an Image object. Does ImageFormat.Icon require 32x32
to create, and if so, why am I able to assign it using
Icon.FromHandle(SHI.hIcon) when I use SHGetFileInfo to retrieve the
icons; I suppose because the icon already exists in memory?

I tried using the routine below with various image formats to save in
something other than Icon format but the transparency is always lost,
and since I am loading Icons, I can't set the ImageList Transparent
color, as I need true transparency.

For now, I am using the large icon for both large and small image
lists and letting the small image list shrink the image to 16 x 16.
But, the image quality is not as good.

Any advise would be greatly appreciated. Thanks in advance.
Nov 20 '05 #1
3 2730
Hi,

Try this instead of return image.fromstream
Dim ico As New Icon(loMemoryStream, 16, 16) ' for large icons use 32, 32

Return ico

Ken

-----------------------------

"Tony Lugg" <to**@lugg.com> wrote in message
news:a1**************************@posting.google.c om...
I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them back when I open the form.

Here's the problem: the large icons load fine but the small ones give
an error stating "Invalid Parameter Used". Below are the two routines
for saving and loading the icons:

Public Function IconToBytes(ByVal icon As Icon) As Byte()
'Converts an Icon object into an array of bytes so
'it can be saved to a database field
Dim loMemoryStream As New IO.MemoryStream
icon.Save(loMemoryStream)
Dim laIcon(loMemoryStream.Length - 1) As Byte
loMemoryStream.Position = 0
loMemoryStream.Read(laIcon, 0, loMemoryStream.Length)
Return laIcon
End Function

Public Function DataFieldToImage(ByVal oField As Object) As Image
'Converts an array of bytes to an Icon object when read
'from a database field.
If Not IsDBNull(oField) Then
Dim laImage() As Byte = oField
Dim loMemoryStream As New IO.MemoryStream(laImage)
Return Image.FromStream(loMemoryStream)
Else
Return Nothing
End If
End Function

I could not figure out how to load directly into an Icon object, so it
is loading into an Image object. Does ImageFormat.Icon require 32x32
to create, and if so, why am I able to assign it using
Icon.FromHandle(SHI.hIcon) when I use SHGetFileInfo to retrieve the
icons; I suppose because the icon already exists in memory?

I tried using the routine below with various image formats to save in
something other than Icon format but the transparency is always lost,
and since I am loading Icons, I can't set the ImageList Transparent
color, as I need true transparency.

For now, I am using the large icon for both large and small image
lists and letting the small image list shrink the image to 16 x 16.
But, the image quality is not as good.

Any advise would be greatly appreciated. Thanks in advance.

Nov 20 '05 #2
Thank you Ken, the 16x16 icons are now being displayed. However,
there is now another minor (hopefully) issue - the 16x16 icon's
transparent background displays as black (32x32 is fine). If I
display the associated icon directly, as I do when I first add a
document to the list, it displays properly, but after saving to the
database and reloading, the backgroud is black. Below is the
definition of the image list:

Me.imglstSmallIcons.ImageSize = New System.Drawing.Size(16, 16)
Me.imglstSmallIcons.TransparentColor =
System.Drawing.Color.Transparent

Any idea what might be causing this?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:<uf*************@TK2MSFTNGP12.phx.gbl>...
Hi,

Try this instead of return image.fromstream
Dim ico As New Icon(loMemoryStream, 16, 16) ' for large icons use 32, 32

Return ico

Ken

-----------------------------

"Tony Lugg" <to**@lugg.com> wrote in message
news:a1**************************@posting.google.c om...
I have an application with a document management form. When users add
documents to the form, I call the API function SHGetFileInfo to get
the associated large and small icons for the file. These icons are
added to two ImageList objects which are bound to a ListView control,
and everything looks great. I am saving the icons to a SQL Server
table by using Icon.Save to a stream and assigning the byte array to
the field, then loading them back when I open the form.

Here's the problem: the large icons load fine but the small ones give
an error stating "Invalid Parameter Used". Below are the two routines
for saving and loading the icons:

Public Function IconToBytes(ByVal icon As Icon) As Byte()
'Converts an Icon object into an array of bytes so
'it can be saved to a database field
Dim loMemoryStream As New IO.MemoryStream
icon.Save(loMemoryStream)
Dim laIcon(loMemoryStream.Length - 1) As Byte
loMemoryStream.Position = 0
loMemoryStream.Read(laIcon, 0, loMemoryStream.Length)
Return laIcon
End Function

Public Function DataFieldToImage(ByVal oField As Object) As Image
'Converts an array of bytes to an Icon object when read
'from a database field.
If Not IsDBNull(oField) Then
Dim laImage() As Byte = oField
Dim loMemoryStream As New IO.MemoryStream(laImage)
Return Image.FromStream(loMemoryStream)
Else
Return Nothing
End If
End Function

I could not figure out how to load directly into an Icon object, so it
is loading into an Image object. Does ImageFormat.Icon require 32x32
to create, and if so, why am I able to assign it using
Icon.FromHandle(SHI.hIcon) when I use SHGetFileInfo to retrieve the
icons; I suppose because the icon already exists in memory?

I tried using the routine below with various image formats to save in
something other than Icon format but the transparency is always lost,
and since I am loading Icons, I can't set the ImageList Transparent
color, as I need true transparency.

For now, I am using the large icon for both large and small image
lists and letting the small image list shrink the image to 16 x 16.
But, the image quality is not as good.

Any advise would be greatly appreciated. Thanks in advance.

Nov 20 '05 #3
I found an alternate way to accomplish what I needed. Instead of
storing the large and small icons in a databse table, I was able to
set the USEFILEATTRIBUTES flag for the SHGetFileInfo function which
does not require access to the file itself - in fact I only need pass
in the file extention to retrieve the associated icons.
Nov 20 '05 #4

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

Similar topics

0
by: Gary Cote | last post by:
>Description: I've recently compiled mysql 4.0.14 on redhat 8.0. The installation fails, however, when running mysql_install_db. I've attached a transcript below. I gather from searching the...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
0
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
8
by: neoedmund | last post by:
any simple method?
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
1
by: rirby2 | last post by:
Hi everyone, I'm currently having a rendering problem in IE7 (haven't even tried the lower IEs yet), vs. what I see in FF2. The simplified site can be found at solerasd.com . (There are more...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
2
by: swethak | last post by:
Hi, I am developing the google application. In my google.js file consists the icon1=new GIcon(); icon1.image = "images/bmw-small.png"; icon1.shadow = "images/shadow50.png";...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.