473,883 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al 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(loMem oryStream)
Dim laIcon(loMemory Stream.Length - 1) As Byte
loMemoryStream. Position = 0
loMemoryStream. Read(laIcon, 0, loMemoryStream. Length)
Return laIcon
End Function

Public Function DataFieldToImag e(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.FromStrea m(loMemoryStrea m)
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.Ico n 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 2763
Hi,

Try this instead of return image.fromstrea m
Dim ico As New Icon(loMemorySt ream, 16, 16) ' for large icons use 32, 32

Return ico

Ken

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

"Tony Lugg" <to**@lugg.co m> wrote in message
news:a1******** *************** ***@posting.goo gle.com...
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(ByV al 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(loMem oryStream)
Dim laIcon(loMemory Stream.Length - 1) As Byte
loMemoryStream. Position = 0
loMemoryStream. Read(laIcon, 0, loMemoryStream. Length)
Return laIcon
End Function

Public Function DataFieldToImag e(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.FromStrea m(loMemoryStrea m)
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.Ico n 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.imglstSmallI cons.ImageSize = New System.Drawing. Size(16, 16)
Me.imglstSmallI cons.Transparen tColor =
System.Drawing. Color.Transpare nt

Any idea what might be causing this?

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message news:<uf******* ******@TK2MSFTN GP12.phx.gbl>.. .
Hi,

Try this instead of return image.fromstrea m
Dim ico As New Icon(loMemorySt ream, 16, 16) ' for large icons use 32, 32

Return ico

Ken

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

"Tony Lugg" <to**@lugg.co m> wrote in message
news:a1******** *************** ***@posting.goo gle.com...
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(ByV al 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(loMem oryStream)
Dim laIcon(loMemory Stream.Length - 1) As Byte
loMemoryStream. Position = 0
loMemoryStream. Read(laIcon, 0, loMemoryStream. Length)
Return laIcon
End Function

Public Function DataFieldToImag e(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.FromStrea m(loMemoryStrea m)
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.Ico n 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 USEFILEATTRIBUT ES 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
624
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 'net that this isn't an entirely unusual thing to happen, and is likely the result of some misconfiguration on my part, or perhaps a version incompatability with my libc. Unfortunately, I haven't seen any concrete suggestions on how to get past it.
6
3822
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 is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is less than or equal to 1249 then no problem.
0
1501
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 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...
8
2894
by: neoedmund | last post by:
any simple method?
2
2970
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 namespace="System.Web.UI.WebControls" %> <%@ import namespace="System.Data" %> <%@ import namespace="System.Data.OleDb" %>
1
5175
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 FF, IE6 and IE7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Employee Listing </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords"...
1
3133
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 image elements that belong in the list but I've only posted 2 since it replicates the problem and minimizes the code to read. In FF, you should see a logo with two images (currently not HREF's) of the same size below it, and a copyright statement below...
2
3163
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 message as in alert box as " Internet Explorer cannot open the Internet site http://google.citycarrentals.com.au/viewalllocations.php . Operation aborted". It is working in Mozilla . Here i mentioned my code . I am facing this problem several...
2
2092
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"; icon1.iconSize = new GSize(25, 25);
0
9933
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9781
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9564
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5791
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.