Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleImageWinApi.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example ExampleImageWinApi.cpp
27  @relates ImageIO
28  @brief demonstrates loading a .bmp file
29  via MS Windows system calls without any third party library.
30  @ingroup g_examples
31  @author woetzel
32 */
33 
34 #include <bias_config.h>
35 
36 #include <Base/Debug/Error.hh>
37 #include <Base/Image/ImageBase.hh>
38 #include <Base/Image/ImageIO.hh>
39 #include <Base/Common/FileHandling.hh>
40 #include <iostream>
41 
42 
43 using namespace std;
44 using namespace BIAS;
45 
46 
47 // globals
48 // filename
49 string fn = BIAS_TESTS_DATA "r4_small.bmp";
50 // run a darttest?
51 bool darttest=false;
52 
53 
54 // parse command line parameters
55 int parseCmdLine(int argc, char** argv){
56 
57  // parse args
58  if (argc>1) {
59  if (strcmp(argv[1],"-darttest")==0){
60  if (argc>2){
61  darttest=true;
62  fn=argv[2]; // exe --darttest <file.bmp>
63  } else {
64  fn=argv[1]; // exe <file.bmp>
65  }
66  }
67  }
68  return 0;
69 }
70 
71 // usage:
72 // ExampleImageWinApi [--darttest] [<file.bmp>]
73 int main( int argc, char** argv)
74 {
75  if (argc>0)
76  cout<<"started "<<argv[0]<<endl;
77 
78  parseCmdLine(argc, argv);
79 
80  // check if file exists/readable at all
82  cout<<"file "<<fn<<" does not exists/is unreadable due to file system problems!";
83  return -1;
84  }
85 
86  ImageBase img;
87  // load the image (bmp)
88  int res = ImageIO::Import_BITMAP_winapi(fn, img );
89  // check result
90  if (res==0){
91  cout<<"successfully loaded "
92  <<img.GetWidth()<<"x"<<img.GetHeight()<<" image from "<<fn<<endl;
93  } else {
94  cout<<"could not load image from "<<fn<<endl
95  <<"is it a simple BMP file?"<<endl;
96  }
97 
98 #ifdef BIAS_HAVE_OPENCV
99  // show image to screen
100  if (!darttest)
101  img.Display();
102 #endif
103 
104  return 0;
105 }
106 
int Display(const std::string &DestWin, const bool &autoresize, const bool &moveToTopLeft, const bool &waitForKey, const unsigned int &delayMsec=DEFAULT_Display_delay, const float &scale=DEFAULT_32to8_scale, const bool &allowAlphaWindow=false) const
OpenCV onscreen popup display, very useful for fast debugging. (JW)
Definition: ImageBase.cpp:1414
unsigned int GetWidth() const
Definition: ImageBase.hh:312
static bool FileReadable(const std::string &filename)
Checks if the given file exists and is readable on file system.
unsigned int GetHeight() const
Definition: ImageBase.hh:319
This is the base class for images in BIAS.
Definition: ImageBase.hh:102