469,590 Members | 2,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Problems with ImageList.. need help

I have a problem that just cropped up with using an ImageList in my project
I am using VB .NET 200
Problem:

I have existing Form with 2 Image List controls. ImageList16 (for 16x16 Images) and ImageList24 (for 24x24). I have inserted images in each and it has worked fine for months... The System.Drawing.Bitmap properties for these images are PixelFormat=32bppArgb and RawFormat=MemoryBmp with the Horiz and VerticalResolution = 96

I installed DirectX9.0

The next time I went to add a Image to the ImageList all of my new images are being inserted as PixelFormat = Format8bppIndexed and RawFormat = Bmp with the Horiz and VertResolution = 71.9836. This is causing all my new images to not remove the transparent color

I used System Restore points to move my system configuration back prior to DirectX9 but it was to no avail... My images are still being inserted incorrectly. In fact all my older components are also now suffering from the same problem...

Things I've tried...
1. I have tried creating a new Image List but it too has the same proble
2. Changing System Color depth and resolution in different combination
Nothing has worked... I have months invested in this program and need help... The old images still work fine but I desperately need to be able to add new images. Any help or suggestions would be appreciated

Thanks

David

Nov 20 '05 #1
4 3884
Hi David,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that after you install directx9.0b, the
imagelist will not work on your machine.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Is the DirectX 9.0b you have installed the one in the windows update
website, or is it a runtime or a directx 9.0 sdk?
Based on my knowledge, the DirectX library will not impact the ImageList
which will use the comctl32.dll underlying.

Also I can not reprodue the problem that all the new image added into the
imagelist are all PixelFormat = Format8bppIndexed and RawFormat = Bmp, on
my side the two properties will depend on the real format of the image.

Have you tried to create a new windows form project and add a imagelist
,and then add a few pictures into the imagelist, did the problem persists?
If no, can you build a simple reproduce sample and post here or send to me
by removing the "online" from my email address.

But I can reproduce the problem that we can not change the transparentcolor
of the imagelist in the IDE designer. As a workaround, I think we can try
to rebuild the imagelist on the fly everytime we need to change the
transparentcolor.
Here is the code snippet, you may have a try and let me know the result.

<code>

Dim il As ImageList
Private Sub RebuildImageList()
If Not il Is Nothing Then
Me.components.Remove(il)
End If
il.Dispose()
il = Nothing
il = New ImageList
il.ColorDepth = ColorDepth.Depth32Bit
il.ImageSize = New System.Drawing.Size(32, 32)
il.Images.Add(New Bitmap("C:\red.bmp"))
il.Images.Add(New Bitmap("C:\blue.bmp"))
il.Images.Add(New Bitmap("C:\green.bmp"))
Me.components.Add(il)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
components = New System.ComponentModel.Container
il = New ImageList
RebuildImageList()
il.TransparentColor = Color.Blue
For i As Integer = 1 To 12
Me.ListView1.Items.Add(i.ToString(), i Mod 3)
Next
Me.ListView1.LargeImageList = il
End Sub
Shared times As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim c As Integer = times Mod 3
Select Case c
Case 0
RebuildImageList()
il.TransparentColor = Color.Green
Me.ListView1.LargeImageList = il
Case 1
RebuildImageList()
il.TransparentColor = Color.Red
Me.ListView1.LargeImageList = il
Case 2
RebuildImageList()
il.TransparentColor = Color.Blue
Me.ListView1.LargeImageList = il
End Select
times += 1
End Sub

</code>

Please apply my suggestion above and let me know if it helps resolve your
problem.

However, if the problem still persists, please help me collect more
information for further troubleshooting.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Interesting..
I created a new project as suggested and inserted 3 images into the ImageList. All of them were inserted with the same properties for the Image as I pointed out earlier
PixelFormat=Format8bppIndexed, RawFormat=Bmp, Vert & Horiz Resolution = 71.9836, Transparent Color = Magent
All the Images appear in the list of Images with Magenta backgrounds (not shown with transparent backgrounds like I am used to seeing

However when I create a button and set the ImageList property to ImageList1 and ImageIndex to 0 I get the transparent image showing on the button (technically perfect...) But when I check the properties of the Image from the button control properties. The properties are set to
PixelFormat=Format32bppArgB, RawFormat=MemoryBmp, Vert & Horiz Resolution = 96, Transparent Color = 9

Very strange (at least I think so)

Any thoughts.. Is this the correct behaviour for the ImageList
It seems to be working but it makes me a little nervous

Cheers

David
Nov 20 '05 #3
Hi David,

I have got your reproduce sample, since the bitmap in the imagelist has
been serialized into the resource file, the properties of the bitmap I can
see is PixelFormat=Format32bppArgB, RawFormat=MemoryBmp, Vert & Horiz
Resolution = 96, Transparent Color = 96 just as you have pointed out.

Have you tried checked the original bitmap file properties to see what is
its original properties by following the steps below?
1. browse to the bitmap file(e.g. red.bmp) in the windows explorer
2. right click on the red.bmp file and select properties
3. select the Summary tab and observe the image property(if you did not see
the image property please click the advance button)
4. What is the original Bit Depth of the bitmap file and its size? Did it
fit what you have seen before(PixelFormat=Format8bppIndexed, RawFormat=Bmp,
Vert & Horiz Resolution = 71.9836)?

As for the Image Property will be "PixelFormat=Format32bppArgB,
RawFormat=MemoryBmp, Vert & Horiz Resolution = 96, Transparent Color = 96",
I think the behavior is correct, because if we look into the code in the
InitializeComponent sub which was generated by the IDE designer.
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream =
CType(resources.GetObject("ImageList1.ImageStream" ),
System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Green

We will find that the image in the ImageList1 will be retrieve from a
memory stream, so the properties will be MemoryBmp and the size and modify
as we have defined in the imagelist property. The
PixelFormat=Format32bppArgB is to maintain the max available color depth.

So I think we do not need to worry about the RawFormat=MemoryBmp, it will
be handled by the IDE.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4
In reviewing everything it appears that your explanation covers off why the format is being morphed to the different format. You are also correct in the original image being the settings that I was getting on the insert.
What is still odd to me is that the transparent color still appears on the image in the ImageList (but not the original 3 images).

My best guess is that the Image List was copied and pasted from a previous form and perhaps this copying of the ImageList is changing the image properties (probably because of the serializing of the images).

In the meantime I guess that we can close this thread as I think it will probably still work fine. I appreciate your input

Cheers

David
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by MB | last post: by
2 posts views Thread by Bob C. | last post: by
reply views Thread by David | last post: by
4 posts views Thread by Archimed | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.