Results 1 to 11 of 11

Thread: Convert Images upto 31 Formats using FreeImage.dll

  1. #1

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Exclamation Convert Images upto 31 Formats using FreeImage.dll

    Convert images upto 31 formats

    This is a small tutorial on how to convert images using the FreeImage.dll. The project attached only shows 2 type conversions. but if you understand the example project, its very easy to do all the other conversions by yourself.

    supported formats

    FIF_UNKNOWN = -1
    FIF_BMP = 0
    FIF_ICO = 1
    FIF_JPEG = 2
    FIF_JNG = 3
    FIF_KOALA = 4
    FIF_LBM = 5
    FIF_IFF = FIF_LBM
    FIF_MNG = 6
    FIF_PBM = 7
    FIF_PBMRAW = 8
    FIF_PCD = 9
    FIF_PCX = 10
    FIF_PGM = 11
    FIF_PGMRAW = 12
    FIF_PNG = 13
    FIF_PPM = 14
    FIF_PPMRAW = 15
    FIF_RAS = 16
    FIF_TARGA = 17
    FIF_TIFF = 18
    FIF_WBMP = 19
    FIF_PSD = 20
    FIF_CUT = 21
    FIF_XBM = 22
    FIF_XPM = 23
    FIF_DDS = 24
    FIF_GIF = 25
    FIF_HDR = 26
    FIF_FAXG3 = 27
    FIF_SGI = 28
    FIF_EXR = 29
    FIF_J2K = 30
    FIF_JP2 = 31
    Download the attached project to see a working example. but be sure to copy the freeimage.dll mentioned in the below steps in to project path

    Here you go :

    1. http://freeimage.sourceforge.net/

    2. Click Download form the left navigation menus.

    3. Click Download FreeImage 3.11.0 [WIN32]

    4. After download completed. Open the extract the zip and open the folder FreeImage3110Win32

    5. Now open the sample Test vb6 project form this folder
    ...\FreeImage3110Win32\FreeImage\Wrapper\VB6\test

    6. Now attached the module found inside
    ..\FreeImage3110Win32\FreeImage\Wrapper\VB6\mfreeimage to the test project.

    7. Now copy the FreeImage.dll found under
    ..\FreeImage3110Win32_2\FreeImage\Dist\

    Thats all, you now have a working sample project that converts a TIF to PNG

    Code:
    Option Explicit
    ' NOTE :
    ' To run this test program, you will have to copy the FreeImage.dll file
    ' in this directory.
    ' Change also the "test.tif" file name with a path to any tif file on your
    ' hard disk
    '
    Private Sub btnTest_Click()
      Dim dib As Long
      Dim bOK As Long
      ' Load a tif image
      dib = FreeImage_Load(FIF_TIFF, "test.tif", 0)
      
      ' Save this image as PNG
      bOK = FreeImage_Save(FIF_PNG, dib, "test.png", 0)
      
      ' Unload the dib
      FreeImage_Unload (dib)
    
    End Sub
    To set the various file type options in conversion (exampe jpg quolity etc) Read the freeiamge.dll pdf documentaion fond here http://downloads.sourceforge.net/fre...eImage3110.pdf
    Also the Module itself is very descriptive. example,

    Public Enum FREE_IMAGE_SAVE_OPTIONS
    FISO_SAVE_DEFAULT = 0
    FISO_BMP_DEFAULT = BMP_DEFAULT
    FISO_BMP_SAVE_RLE = BMP_SAVE_RLE
    FISO_EXR_DEFAULT = EXR_DEFAULT ' save data as half with piz-based wavelet compression
    FISO_EXR_FLOAT = EXR_FLOAT ' save data as float instead of as half (not recommended)
    FISO_EXR_NONE = EXR_NONE ' save with no compression
    FISO_EXR_ZIP = EXR_ZIP ' save with zlib compression, in blocks of 16 scan lines
    FISO_EXR_PIZ = EXR_PIZ ' save with piz-based wavelet compression
    FISO_EXR_PXR24 = EXR_PXR24 ' save with lossy 24-bit float compression
    FISO_EXR_B44 = EXR_B44 ' save with lossy 44% float compression - goes to 22% when combined with EXR_LC
    FISO_EXR_LC = EXR_LC ' save images with one luminance and two chroma channels, rather than as RGB (lossy compression)
    FISO_JPEG_DEFAULT = JPEG_DEFAULT ' for saving this is a synonym for FISO_JPEG_QUALITYGOOD
    FISO_JPEG_QUALITYSUPERB = JPEG_QUALITYSUPERB ' save with superb quality (100:1)
    FISO_JPEG_QUALITYGOOD = JPEG_QUALITYGOOD ' save with good quality (75:1)
    FISO_JPEG_QUALITYNORMAL = JPEG_QUALITYNORMAL ' save with normal quality (50:1)
    FISO_JPEG_QUALITYAVERAGE = JPEG_QUALITYAVERAGE ' save with average quality (25:1)
    FISO_JPEG_QUALITYBAD = JPEG_QUALITYBAD ' save with bad quality (10:1)
    FISO_JPEG_PROGRESSIVE = JPEG_PROGRESSIVE ' save as a progressive-JPEG (use 'OR' to combine with other save flags)
    FISO_JPEG_SUBSAMPLING_411 = JPEG_SUBSAMPLING_411 ' save with high 4x1 chroma subsampling (4:1:1)
    FISO_JPEG_SUBSAMPLING_420 = JPEG_SUBSAMPLING_420 ' save with medium 2x2 medium chroma subsampling (4:2:0) - default value
    FISO_JPEG_SUBSAMPLING_422 = JPEG_SUBSAMPLING_422 ' save with low 2x1 chroma subsampling (4:2:2)
    FISO_JPEG_SUBSAMPLING_444 = JPEG_SUBSAMPLING_444 ' save with no chroma subsampling (4:4:4)
    FISO_PNG_Z_BEST_SPEED = PNG_Z_BEST_SPEED ' save using ZLib level 1 compression flag (default value is 6)
    FISO_PNG_Z_DEFAULT_COMPRESSION = PNG_Z_DEFAULT_COMPRESSION ' save using ZLib level 6 compression flag (default recommended value)
    FISO_PNG_Z_BEST_COMPRESSION = PNG_Z_BEST_COMPRESSION ' save using ZLib level 9 compression flag (default value is 6)
    FISO_PNG_Z_NO_COMPRESSION = PNG_Z_NO_COMPRESSION ' save without ZLib compression
    FISO_PNG_INTERLACED = PNG_INTERLACED ' save using Adam7 interlacing (use | to combine with other save flags)
    FISO_PNM_DEFAULT = PNM_DEFAULT
    FISO_PNM_SAVE_RAW = PNM_SAVE_RAW ' if set the writer saves in RAW format (i.e. P4, P5 or P6)
    FISO_PNM_SAVE_ASCII = PNM_SAVE_ASCII ' if set the writer saves in ASCII format (i.e. P1, P2 or P3)
    FISO_TIFF_DEFAULT = TIFF_DEFAULT
    FISO_TIFF_CMYK = TIFF_CMYK ' stores tags for separated CMYK (use 'OR' to combine with compression flags)
    FISO_TIFF_PACKBITS = TIFF_PACKBITS ' save using PACKBITS compression
    FISO_TIFF_DEFLATE = TIFF_DEFLATE ' save using DEFLATE compression (a.k.a. ZLIB compression)
    FISO_TIFF_ADOBE_DEFLATE = TIFF_ADOBE_DEFLATE ' save using ADOBE DEFLATE compression
    FISO_TIFF_NONE = TIFF_NONE ' save without any compression
    FISO_TIFF_CCITTFAX3 = TIFF_CCITTFAX3 ' save using CCITT Group 3 fax encoding
    FISO_TIFF_CCITTFAX4 = TIFF_CCITTFAX4 ' save using CCITT Group 4 fax encoding
    FISO_TIFF_LZW = TIFF_LZW ' save using LZW compression
    FISO_TIFF_JPEG = TIFF_JPEG ' save using JPEG compression
    End Enum
    Drawback : You need to distribute a 1.9 MB Weight dll with your project

    The attached project to work, you need to copy the freeimage.dll in to the project path.

    Edited : Convertion form bmp to gif and gray scale formats http://www.vbforums.com/showpost.php...94&postcount=5
    Attached Files Attached Files
    Last edited by Fazi; Jan 19th, 2009 at 06:50 AM.

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Your subject title seems very misleading, I was expecting at least a combo box to select one of the 31 output formats.

  3. #3

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Quote Originally Posted by Edgemeal
    Your subject title seems very misleading, I was expecting at least a combo box to select one of the 31 output formats.
    yes i have not shown all the 31 formats coversions.
    coz i thought that basic example with the steps will give you almost what you needed. also The title only tell here this dll has so much power !

    Any way ill put a note that the example shows only two type of coversions.
    Last edited by Fazi; Jan 19th, 2009 at 12:50 AM.

  4. #4
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Convert Images upto 31 Formats using FreeImage.dll

    i am really developing the same one but for me os is MAC thats much challenging with the domains scripts. anyway thanks fazi for the article..
    Visual Studio.net 2010
    If this post is useful, rate it


  5. #5

    Thread Starter
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Convert to gif

    Code:
    dib = FreeImage_LoadEx(AppDataPath & "\" & "test.bmp")
    If (dib) Then
       Call FreeImage_SaveEx(dib, AppDataPath & "\" & "test.gif")
       Call FreeImage_Unload(dib)
    End If
    Convert to Grayscale
    Code:
    dib = FreeImage_LoadEx(AppDataPath & "\" & "test.bmp")
    dibGray = FreeImage_ConvertToGreyscale(dib)
    bOK = FreeImage_Save(FIF_GIF, dibGray, AppDataPath & "\" & "test.gif", 0)
    Last edited by Fazi; Jan 19th, 2009 at 06:59 AM.

  6. #6
    New Member
    Join Date
    Jul 2011
    Posts
    8

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Is there any way at all that I can include freeimage.dll with Visual Basic 2008 Express Edition?

    I just get this error message when I try and incldue it:


    If there is no way of getting it to work, are there any alternatives that can convert png to pcx?

  7. #7
    Junior Member
    Join Date
    May 2009
    Posts
    26

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Bad thing about this Visual Basic 6 FreeImage example is the 3 lines of code included here are the only online examples I can find anywhere using FreeImage from VB6. It looks like the developer must have spent ages composing the wrapper and a pity that there is no example calls online anywhere to utilize his hard work from MFreeImage.bas.

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Quote Originally Posted by fotonut View Post
    Bad thing about this Visual Basic 6 FreeImage example is the 3 lines of code included here are the only online examples I can find anywhere using FreeImage from VB6. It looks like the developer must have spent ages composing the wrapper and a pity that there is no example calls online anywhere to utilize his hard work from MFreeImage.bas.
    [VB6] Picture/Video Viewer by MartinLiss

    http://www.google.com/search?q=FreeImage.dll+VB6

  9. #9
    Junior Member
    Join Date
    May 2009
    Posts
    26

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Thanks, with the above post to this forum, the google search now works LOL.

    But seriously thank you for a really nice example of using FreeImage from Visual Basic 6. Here are more example calls to FreeImage & VB6:

    https://sourceforge.net/projects/fre.../topic/4752688
    https://sourceforge.net/projects/fre.../topic/4754832

    P.S. Don't you just love www.bigresource.com? I wonder when I will learn to stop clicking on that link? It lists everyone else who has asked the same question as you since the beginning of time, but never anyone who answered it ;-)

  10. #10
    Fanatic Member
    Join Date
    Nov 2011
    Posts
    806

    Re: Convert Images upto 31 Formats using FreeImage.dll

    Does anyone know how to load a Byte array to a Freeimage Dib

    instead of loading a file ie.
    dib = FreeImage_Load(FIF_TIFF, "test.tif", 0)

    would like to load a Byte Array, something like below

    dib = FreeImage_Load(FIF_TIFF, ByteArray() , 0)

    thanks

  11. #11
    New Member
    Join Date
    Nov 2013
    Posts
    11

    Re: Convert Images upto 31 Formats using FreeImage.dll

    I used the following code and it works ok except lighter colors such as yellow are hard to see in grey scale.

    IS there a way to get true B/W?


    dib = FreeImage_LoadEx(App.Path & "\" & "printout0.bmp")

    dibGrey = FreeImage_ConvertToGreyscale(dib)

    bOK = FreeImage_Save(FIF_GIF, dibGrey, App.Path & "\" & "test.gif", 0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width