SOL9 Sample: ImageTuner

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * ImageTuner.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::ImageTuner classes.
This program can be used to tune the color of an image file to 'grayscale', 'sepia tone',
'negative', and 'contrast'.  
 */

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

void _tmain(int argc, TCHAR* argv[])
{
  GdiplusInitializer initializer;
  if (!(argc == 2 || argc ==4)) {
    _tprintf(_T("ImageSizeQuery : %s imageFileName\n"), argv[0]);
    _tprintf(_T("ImageTuning: %s imageFileName saveFileName gray|lightgray|sepia|negative|contrast:scale\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);
    }

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

    //ImageFormat conversion
    if (argc == 4) {
      const TCHAR* saveFileName = argv[2];
      const TCHAR* tuneFormat         = argv[3];
      bool rc = tuner.tune(_bstr_t(imageFileName), _bstr_t(saveFileName), _bstr_t(tuneFormat));
      if (rc) {
        _tprintf(_T("OK. Tuned image file '%s' by color '%s' and saved to '%s'\n"),
          imageFileName, tuneFormat, saveFileName);
      } else {
        _tprintf(_T("Failed to tune '%s' to '%s'\n"),
          imageFileName, saveFileName);
      }
    }
  } catch (Exception& ex) {
    ex.printf();
  }
}

Last modified: 2 May 2016

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