SOL9 Sample: ImageBlender

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// 2012/04/20
/*
This is a sample program based on Windows Gdiplus and SOL::ImageAlphaBlender classes.
 */

#include <sol/ColorTable.h>
#include <sol\gdiplus\GdiplusInitializer.h>
#include <sol\gdiplus\ImageBlender.h>

void _tmain(int argc, TCHAR* argv[])
{
  GdiplusInitializer initializer;
  
  ColorTable colorTable;

  if (!(argc == 2 || argc ==5)) {
    _tprintf(_T("ImageSizeQuery : %s imageFileName\n"), argv[0]);
    _tprintf(_T("ImageBlending: %s imageFileName backColor saveFileName alpha:scale\n"), argv[0]);
    String colors = colorTable.getColorNames();
    _tprintf(_T("backColor takes one of the following values:\n%s\n"), (const TCHAR*)colors);

    return;
  }

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

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

    //Image Alpha-blending 
    if (argc == 5) {
      const TCHAR* color        = argv[2];
      const TCHAR* saveFileName = argv[3];
      const TCHAR* name         = argv[4];

      COLORREF backColor = 0;
      if (!colorTable.get(color, (long*)&backColor)) {
        String colors = colorTable.getColorNames();

        throw Exception(0, _T("Invalid color name %s.\nIt takes one of the following values:\n%s\n"),
          color, (const TCHAR*)colors);
      }

      bool rc = blender.blend(_bstr_t(imageFileName), backColor, _bstr_t(saveFileName), _bstr_t(name));
      if (rc) {
        _tprintf(_T("OK. Alpha-blended '%s' onto color '%s' and saved to '%s'\n"),
          imageFileName, color, saveFileName);
      } else {
        _tprintf(_T("Failed to alpha-blend '%s' onto color '%s' and save to '%s'\n"),
          imageFileName, color, saveFileName);
      }
    }
  } catch (Exception& ex) {
    ex.printf();
  }
}

Last modified: 2 May 2016

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