SOL9 Sample: ImageConverter

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ImageConverter.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// 2012/04/10
/*
This is a sample program based on Windows Gdiplus and SOL::ImageConverter classes.
This program can be used to convert an image file to a file of other image 
formats (BMP, JPG, PNG, GIF, TIF).
 */

#include <sol\gdiplus\GdiplusInitializer.h>
#include <sol\gdiplus\ImageConverter.h>

void _tmain(int argc, TCHAR* argv[])
{
  GdiplusInitializer initializer;
  if (!(argc == 2 || argc ==3)) {
    _tprintf(_T("ImageSizeQuery : %s imageFileName\n"), argv[0]);
    _tprintf(_T("ImageConversion: %s imageFileName saveFileName\n"), argv[0]);

    return;
  }

  try {
    const TCHAR* imageFileName = argv[1];
    
    File file;
    if (file.isExistent(imageFileName) == FALSE) {
      throw Exception(0, _T("File not found :'%s'"), imageFileName);
    }

    ImageConverter converter;
    
    //ImageSize query
    if (argc == 2) {
      int width = 0, height = 0;
      if (converter.getImageSize(_bstr_t(imageFileName), width, height)) {
        _tprintf(_T("Width = %d Height = %d for ImageFile '%s'\n"),
          width, height, imageFileName);
      }
    }

    //ImageFormat conversion
    if (argc == 3) {
      const TCHAR* saveFileName  = argv[2];

      bool rc = converter.convert(_bstr_t(imageFileName), _bstr_t(saveFileName));
      if (rc) {
        _tprintf(_T("OK. Converted '%s' to '%s'\n"),
          imageFileName, saveFileName);
      } else {
        _tprintf(_T("Failed to convert '%s' to '%s'\n"),
          imageFileName, saveFileName);
      }
    }
  } catch (Exception& ex) {
    ex.printf();
  }
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.