Results 1 to 11 of 11

Thread: Convert Images upto 31 Formats using FreeImage.dll

Threaded View

  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.

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