SOL9 Sample: ImageResizer

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ImageResizer.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::ImageResizer classes.
This program can be used to resize an image file to a file with specified width and height
of other image formats (BMP, JPG, PNG, GIF, TIF).
 */

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


void _tmain(int argc, TCHAR* argv[])
{
  GdiplusInitializer initializer;
  if (!(argc == 2 || argc == 4)) {
    _tprintf(_T("ImageSizeQuery: %s imageFileName\n"), argv[0]);
    _tprintf(_T("ImageResizing : %s imageFileName saveFileName percentage%|width,*|*,height|wdth,height\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);
    }

    ImageResizer resizer;

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


    //Image resizing
    if (argc == 4) {
      const TCHAR* saveFileName  = argv[2];
      const TCHAR* resizeParam   = argv[3];

      bool rc = resizer.resize(_bstr_t(imageFileName), _bstr_t(saveFileName), resizeParam);

      if (rc) {
        _tprintf(_T("OK. Resized %s to %s\n"),
          imageFileName, saveFileName);
      } else {
        _tprintf(_T("Failed to resize %s to %s\n"),
          imageFileName, saveFileName);
      }
    }
  } catch (Exception& ex) {
    ex.printf();
  }
}

Last modified: 2 May 2016

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