SOL9 Sample: ImageClipper

SOL9 2.0 Samples

1 Screenshot


2 Source code

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

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


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

    ImageClipper clipper;

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

    //Image clipping
    if (argc == 7) {
      const TCHAR* saveFileName  = argv[2];
      const int x     = atoi(argv[3]);
      const int y     = atoi(argv[4]);
      const int width = atoi(argv[5]);
      const int height= atoi(argv[6]);

      bool rc = clipper.clip(_bstr_t(imageFileName), _bstr_t(saveFileName),
        x, y, width, height);
      if (rc) {
        _tprintf(_T("OK. Clipped %s to %s\n"),
          imageFileName, saveFileName);
      } else {
        _tprintf(_T("Failed to clip %s to %s\n"),
          imageFileName, saveFileName);
      }
    }
  } catch (Exception& ex) {
    ex.printf();
  }
}

Last modified: 2 May 2016

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