Problems with ImageList.. need help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    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=32b ppArgb and RawFormat=Memor yBmp with the Horiz and VerticalResolut ion = 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 = Format8bppIndex ed 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

  • Peter Huang

    #2
    RE: Problems with ImageList.. need help

    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 = Format8bppIndex ed 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 transparentcolo r
    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
    transparentcolo r.
    Here is the code snippet, you may have a try and let me know the result.

    <code>

    Dim il As ImageList
    Private Sub RebuildImageLis t()
    If Not il Is Nothing Then
    Me.components.R emove(il)
    End If
    il.Dispose()
    il = Nothing
    il = New ImageList
    il.ColorDepth = ColorDepth.Dept h32Bit
    il.ImageSize = New System.Drawing. Size(32, 32)
    il.Images.Add(N ew Bitmap("C:\red. bmp"))
    il.Images.Add(N ew Bitmap("C:\blue .bmp"))
    il.Images.Add(N ew Bitmap("C:\gree n.bmp"))
    Me.components.A dd(il)
    End Sub
    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load
    components = New System.Componen tModel.Containe r
    il = New ImageList
    RebuildImageLis t()
    il.TransparentC olor = Color.Blue
    For i As Integer = 1 To 12
    Me.ListView1.It ems.Add(i.ToStr ing(), i Mod 3)
    Next
    Me.ListView1.La rgeImageList = il
    End Sub
    Shared times As Integer = 0
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim c As Integer = times Mod 3
    Select Case c
    Case 0
    RebuildImageLis t()
    il.TransparentC olor = Color.Green
    Me.ListView1.La rgeImageList = il
    Case 1
    RebuildImageLis t()
    il.TransparentC olor = Color.Red
    Me.ListView1.La rgeImageList = il
    Case 2
    RebuildImageLis t()
    il.TransparentC olor = Color.Blue
    Me.ListView1.La rgeImageList = 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.

    Comment

    • David

      #3
      RE: Problems with ImageList.. need help

      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=For mat8bppIndexed, 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=For mat32bppArgB, RawFormat=Memor yBmp, 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

      Comment

      • Peter Huang

        #4
        RE: Problems with ImageList.. need help

        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=For mat32bppArgB, RawFormat=Memor yBmp, 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(PixelFor mat=Format8bppI ndexed, RawFormat=Bmp,
        Vert & Horiz Resolution = 71.9836)?

        As for the Image Property will be "PixelFormat=Fo rmat32bppArgB,
        RawFormat=Memor yBmp, Vert & Horiz Resolution = 96, Transparent Color = 96",
        I think the behavior is correct, because if we look into the code in the
        InitializeCompo nent sub which was generated by the IDE designer.
        '
        'ImageList1
        '
        Me.ImageList1.I mageSize = New System.Drawing. Size(16, 16)
        Me.ImageList1.I mageStream =
        CType(resources .GetObject("Ima geList1.ImageSt ream"),
        System.Windows. Forms.ImageList Streamer)
        Me.ImageList1.T ransparentColor = 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=For mat32bppArgB is to maintain the max available color depth.

        So I think we do not need to worry about the RawFormat=Memor yBmp, 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.

        Comment

        • David

          #5
          RE: Problems with ImageList.. need help

          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

          Comment

          Working...