SOL9 Sample: ImageBrowser

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.07.26
// 2008/09/16 Modified to use restoreFileFolder/saveFileFolder.

#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\FileDialog.h>
#include <sol\ClientDC.h>
#include <sol\DIBSection.h>
#include <sol\AffineTransform.h>
#include <sol\HighlightFilter.h>
#include <sol\GrayScaleFilter.h>
#include "resource.h"

namespace SOL {

class ImageBrowser :public ApplicationView {

private:
  DIBSection  loadedImage;
  FileDialog  fileDialog;
  DIBSection*  rotatedImage;
  DIBSection* grayImage;

  DIBSection*  brightImage;

public:
  /**
   * Constructor
   */
  ImageBrowser(Application& applet, const TCHAR* label, Args& args)
    :ApplicationView(applet, label, args)
  {
    grayImage    = NULL;
    brightImage  = NULL;
    rotatedImage = NULL;
    
    ClientDC cdc(this);

    Args ar;
    ar.set(XmNfilter, _T("BitmapFiles (*.bmp)\0 *.bmp\0"));
    fileDialog.create(this, _T(""), ar);

    addCallback(XmNmenuCallback, IDM_OPEN, this,
      (Callback)&ImageBrowser::open, NULL);
  
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&ImageBrowser::exit, NULL);

    addEventHandler(WM_PAINT, this, 
      (Handler)&ImageBrowser::paint, NULL);
    addEventHandler(WM_CLOSE, this, 
      (Handler)&ImageBrowser::close, NULL);

    restorePlacement();
  }

public:
  /**
   * Destructor
   */
  ~ImageBrowser() {
    delete grayImage;
    delete brightImage;
    delete rotatedImage;
  }

private:
  long  close(Event& event) 
  {
    savePlacement();
    return defaultProc(event);
  }

private:
  /**
   * ID_OPEN menu callback
   */
  void  open(Action& action) {
    //2008/09/16
    TCHAR dir[_MAX_PATH];
    if (restoreFileFolder(dir, CountOf(dir))) { //2012/06/26
      Args ar;
      ar.set(XmNdirectory, dir);
      fileDialog.setValues(ar);
    }

    if (fileDialog.open()) {
      TCHAR title[MAX_PATH];
      TCHAR* filename = fileDialog.getFileName();
      ClientDC cdc(this);

      //Load an original image.
      loadedImage.load(cdc, filename);
      //2008/09/16
      saveFileFolder(filename);

      //Apply a GrayScaleFilter       
      GrayScaleFilter gfilter;

      delete grayImage;
      grayImage = gfilter.filterRGB(cdc, loadedImage);

      //Apply a HighlightFilter           
      HighlightFilter hfilter(40);
    
      delete brightImage;
      brightImage = hfilter.filterRGB(cdc, loadedImage);
      
      //Apply an AffineTransformation.  
      AffineTransform transform;
      
      delete rotatedImage;
      rotatedImage = transform.rotate(cdc, loadedImage, 30.0);

      _stprintf_s(title, CountOf(title), _T("%s - ImageBrowser"), filename);
      setText(title);

      //Force to redraw.
      update(NULL);
    }
  }

private:
  /**
   * WM_PAINT event handler.
   */
  long paint(Event& event)
  {
    PaintDC pdc(this);
    loadedImage.draw(pdc, 10, 10);
    int gap = 100;
    if (grayImage) {
      grayImage->draw(pdc, 10+gap, 10+gap);
    }
  
    if (brightImage) {
      brightImage->draw(pdc, 10+gap*2, 10+gap*2);
    }
    
    if (rotatedImage) {
      rotatedImage->draw(pdc, 10+gap*3, 10+gap*3);
    }

    return 0;
  }

};

}

/////////////////////////////////////////////
// Program Main
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);

    Args args;
    args.set(XmNexStyle,(ulong)WS_EX_CLIENTEDGE);

    ImageBrowser imageTransform(applet, name, args);
    imageTransform.realize();
    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}

Last modified: 1 Feb 2017

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