none
Convert icon file To BMP file

    Question

  •  Dim outBitmap As Bitmap 
     Dim tmpIcon1 As Icon = (Icon.ExtractAssociatedIcon(f))
      outBitmap = tmpIcon1.ToBitmap
      outBitmap.Save(destName, iFormat)
      picturebox1.BackgroundImage = outBitmap


    I've reduced my massive test code to the above for this post.

    In the above iFormat is the BMP image format.

    The picture box displays the correct image but the saved image shows in Windows Explorer and Paint as all black.

    Do you know how to fix this?

     

    Thanks


    Frank
    dimanche 21 août 2011 14:25

Réponses

  • Keep in mind that many Icons will use transparency (alpha) color values which a 24bit bmp file cannot represent.  This often leads to transparent pixels being rendered as black, so depending on what that source icon looks like (as well as its internal formats - remember that an Icon can hold various images of differing sizes and color depth), you may need to save the file as a PNG instead of a BMP, or perform some color conversion on the source image before saving it to disk.

     


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Marqué comme réponse Frank Q99 dimanche 21 août 2011 18:50
    dimanche 21 août 2011 16:24

Toutes les réponses

  • It seems to work fine based on my experiments. However, if picturebox is showing correct image, then try:

    picturebox1.Image.Save("c:\icon.bmp", Imaging.ImageFormat.Bmp)

    HTH.


    Best regards, Saygılarımla, Onur Güzel

    Yazgeliştir Forumları VB.NET / C# Süper Moderatorü.

    Microsoft Haber Grupları Profilim (VB.NET)


    dimanche 21 août 2011 14:33
  • As far as i know, that is MSpaint issue, any image file saved from graphics class in .net always turn black. If you have other image program such as fireworks or photoshop, you will that the image is saved with correct format. 

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    dimanche 21 août 2011 16:18
  • Thanks for the reply.

    I should have said: I tried it on about 8 files and 3 worked OK. The others functioned (i.e, failed) as described. I can't find common properties among the working or failing files that might explain it.

     I wonder if some icon files can be indexed and some not indexed?

    If so, how to check?

    I didn't think:

    picturebox1.BackgroundImage.Save, destName, Imaging.ImageFormat.Bmp)

    would make any difference since I believe picturebox1.BackgroundImage and outBitmap both reference the same object. But I tried anyway and there is no difference.

    I also tried:

    Dim bm As Bitmap = New Bitmap(outBitmap.Width, outBitmap.Height, outBitmap.PixelFormat)

    Dim gr As Graphics = Graphics.FromImage(bm)

    gr.DrawImage(outBitmap, 0, 0, 12, 12)

    bm.Save(dstName, iFormat)

    pb.BackgroundImage = bm

    and get the same 32x32 black image saved.

    The picturebox shows the smaller image.

     

     


    Frank
    dimanche 21 août 2011 16:24
  • Keep in mind that many Icons will use transparency (alpha) color values which a 24bit bmp file cannot represent.  This often leads to transparent pixels being rendered as black, so depending on what that source icon looks like (as well as its internal formats - remember that an Icon can hold various images of differing sizes and color depth), you may need to save the file as a PNG instead of a BMP, or perform some color conversion on the source image before saving it to disk.

     


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    • Marqué comme réponse Frank Q99 dimanche 21 août 2011 18:50
    dimanche 21 août 2011 16:24
  •            Dim bm As Bitmap = New Bitmap(outBitmap.Width, outBitmap.Height, PixelFormat.Format32bppArgb)
                    Dim gr As Graphics = Graphics.FromImage(bm)
                    gr.DrawImage(outBitmap, 0, 0, 12, 12)
                    bm.Save(destFolder & "\" & "2" & dstName, ImageFormat.Png)
                    pb.BackgroundImage = bm

    That did it. The above works OK.

    Now that I got that going I think I'll be able to get it to do what I want.

    Thanks


    Frank
    dimanche 21 août 2011 18:50