c# - Transparency in FreeImage goes crazy -


in program want load png or ico file (with transparency) , save ico file transparency.

this random png image testing:

enter image description here

...as can see haves transparency.

but when try convert ico result:

enter image description here

(picture taken windows explorer)

all black color lost.

i've tried same conversion using profesional software photoshop, or toycon , result ico file don't have problem.

this code, first time i'm using freeimage , don't know images , alpha-channels or transparency:

imports freeimageapi  'dim img freeimageapi.fibitmap = freeimage.load(format, file, free_image_load_flags.ico_makealpha)  public class form1  dim file string = "c:\users\administrador.elektro-pc\desktop\auricular 5.png"  private sub form1_load(sender object, e eventargs) handles mybase.shown      dim format freeimageapi.free_image_format = freeimage.getfiletype(file, 32)      dim img freeimageapi.fibitmap = freeimage.loadex(file)      dim transparency byte() = new byte(0) {}      freeimage.settransparencytable(img, transparency)      freeimage.save(free_image_format.fif_ico, img, "c:\test.ico", free_image_save_flags.default)  end sub  end class 

done.

i've deleted transparency table , seems working fine, no need set transparency @ last, did newbie helper class manage basic functions of library (convert image, rotate, grayscale, resize...) in easy way:

#region " freeimage helper "  ' [ freeimage helper ] ' ' // elektro h@cker ' ' ' instructions: ' 1. add reference "freeimagenet.dll" in project. ' 2. add "freeimage.dll" in project. ' ' ' examples : ' ' msgbox(freeimagehelper.is_avaliable() ' result: true ' msgbox(freeimagehelper.get_version()  ' result: 3.15.1 ' msgbox(freeimagehelper.get_imageformat("c:\test.png")) ' result: png ' ' freeimagehelper.convert("c:\test.png", "c:\test.ico", freeimageapi.free_image_format.fif_ico) ' freeimagehelper.convert(new bitmap("c:\test.png"), "c:\test.jpg", freeimageapi.free_image_format.fif_jpeg, freeimageapi.free_image_save_flags.jpeg_subsampling_444 or freeimageapi.free_image_save_flags.jpeg_qualitysuperb) ' ' picturebox1.backgroundimage = freeimagehelper.grayscale(new bitmap("c:\test.bmp")) ' picturebox1.backgroundimage = freeimagehelper.grayscale("c:\test.bmp") ' ' picturebox1.backgroundimage = freeimagehelper.resize(new bitmap("c:\test.bmp"), 32, 32) ' picturebox1.backgroundimage = freeimagehelper.resize("c:\test.bmp", 64, 128) ' ' picturebox1.backgroundimage = freeimagehelper.rotate(new bitmap("c:\test.bmp"), 90) ' picturebox1.backgroundimage = freeimagehelper.rotate("c:\test.bmp", -90) ' ' picturebox1.backgroundimage = freeimagehelper.thumbnail(new bitmap("c:\test.png"), 64, true) ' picturebox1.backgroundimage = freeimagehelper.thumbnail("c:\test.png", 64, true)    imports freeimageapi  public class freeimagehelper  ' <summary> ' checks if <i>freeimage.dll</i> avaliable on system. ' </summary> public shared function is_avaliable() boolean     return freeimage.isavailable end function  ' <summary> ' gets version of freeimage.dll. ' </summary> shared function get_version() string     return freeimage.getversion end function  ' <summary> ' gets image format of image file. ' </summary> shared function get_imageformat(byval file string) string     return freeimage.getfiletype(file, 0).tostring.substring(4) end function  ' <summary> ' convert bitmap object between image formats , save disk. ' </summary> shared sub convert(byval bmp system.drawing.bitmap, _                    byval output string, _                    byval newformat free_image_format, _                    optional byval saveflags free_image_save_flags = free_image_save_flags.default)      try         freeimage.savebitmap(bmp, output, newformat, saveflags)     catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)     end try  end sub  ' <summary> ' convert image file between image formats , save disk. ' </summary> shared sub convert(byval file string, _                    byval output string, _                    byval newformat free_image_format, _                    optional byval saveflags free_image_save_flags = free_image_save_flags.default)      try         freeimage.save(newformat, freeimage.loadex(file), output, saveflags)     catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)     end try  end sub  ' <summary> ' grayscales bitmap object. ' </summary> shared function grayscale(byval bmp system.drawing.bitmap) system.drawing.bitmap      try          dim imagestream new system.io.memorystream         bmp.save(imagestream, bmp.rawformat)          dim image fibitmap = freeimage.loadfromstream(imagestream)         imagestream.dispose()          return freeimage.getbitmap(freeimage.converttogreyscale(image))      catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' grayscales image file. ' </summary> shared function grayscale(byval file string) system.drawing.bitmap      try         return freeimage.getbitmap(freeimage.converttogreyscale(freeimage.loadex(file)))     catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' resizes bitmap object. ' </summary> shared function resize(byval bmp system.drawing.bitmap, _                        byval x int32, _                        byval y int32, _                        optional byval quality free_image_filter = free_image_filter.filter_bilinear) system.drawing.bitmap      try          dim imagestream new system.io.memorystream         bmp.save(imagestream, bmp.rawformat)          dim image fibitmap = freeimage.loadfromstream(imagestream)         imagestream.dispose()          return freeimage.getbitmap(freeimage.rescale(image, x, y, quality))      catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' resizes image file. ' </summary> shared function resize(byval file string, _                        byval x int32, _                        byval y int32, _                        optional byval quality free_image_filter = free_image_filter.filter_bilinear) system.drawing.bitmap      try          return freeimage.getbitmap(freeimage.rescale(freeimage.loadex(file), x, y, quality))      catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' rotates bitmap object. ' </summary> shared function rotate(byval bmp system.drawing.bitmap, _                        byval angle double) system.drawing.bitmap      try          dim imagestream new system.io.memorystream         bmp.save(imagestream, bmp.rawformat)          dim image fibitmap = freeimage.loadfromstream(imagestream)         imagestream.dispose()          return freeimage.getbitmap(freeimage.rotate(image, angle))      catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' rotates image file. ' </summary> shared function rotate(byval file string, _                        byval angle double) system.drawing.bitmap      try          return freeimage.getbitmap(freeimage.rotate(freeimage.loadex(file), angle))      catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' returns thumbnail of bitmap object. ' </summary> shared function thumbnail(byval bmp system.drawing.bitmap, _                                byval size int32, _                                byval convert boolean) system.drawing.bitmap      try          dim imagestream new system.io.memorystream         bmp.save(imagestream, bmp.rawformat)          dim image fibitmap = freeimage.loadfromstream(imagestream)         imagestream.dispose()          return freeimage.getbitmap(freeimage.makethumbnail(image, size, convert))      catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  ' <summary> ' returns thumbnail of image file. ' </summary> shared function thumbnail(byval file string, _                                byval size int32, _                                byval convert boolean) system.drawing.bitmap      try         return freeimage.getbitmap(freeimage.makethumbnail(freeimage.loadex(file), size, convert))     catch ex exception         ' throw new exception(ex.message)         msgbox(ex.message)         return nothing     end try  end function  end class  #end region 

Comments