Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleImageWinApi.cpp

demonstrates loading a .bmp file via MS Windows system calls without any third party library.

Author
woetzel
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleImageWinApi.cpp
@relates ImageIO
@brief demonstrates loading a .bmp file
via MS Windows system calls without any third party library.
@ingroup g_examples
@author woetzel
*/
#include <bias_config.h>
#include <Base/Debug/Error.hh>
#include <Base/Image/ImageBase.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Common/FileHandling.hh>
#include <iostream>
using namespace std;
using namespace BIAS;
// globals
// filename
string fn = BIAS_TESTS_DATA "r4_small.bmp";
// run a darttest?
bool darttest=false;
// parse command line parameters
int parseCmdLine(int argc, char** argv){
// parse args
if (argc>1) {
if (strcmp(argv[1],"-darttest")==0){
if (argc>2){
darttest=true;
fn=argv[2]; // exe --darttest <file.bmp>
} else {
fn=argv[1]; // exe <file.bmp>
}
}
}
return 0;
}
// usage:
// ExampleImageWinApi [--darttest] [<file.bmp>]
int main( int argc, char** argv)
{
if (argc>0)
cout<<"started "<<argv[0]<<endl;
parseCmdLine(argc, argv);
// check if file exists/readable at all
cout<<"file "<<fn<<" does not exists/is unreadable due to file system problems!";
return -1;
}
ImageBase img;
// load the image (bmp)
int res = ImageIO::Import_BITMAP_winapi(fn, img );
// check result
if (res==0){
cout<<"successfully loaded "
<<img.GetWidth()<<"x"<<img.GetHeight()<<" image from "<<fn<<endl;
} else {
cout<<"could not load image from "<<fn<<endl
<<"is it a simple BMP file?"<<endl;
}
#ifdef BIAS_HAVE_OPENCV
// show image to screen
if (!darttest)
img.Display();
#endif
return 0;
}