Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDrawTextWx.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Vision N GmbH
5  Schauenburgerstr. 116
6  24118 Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
21 
22 
23 /**
24  @example ExampleDrawTextWx.cpp
25  @relates DrawTextWx
26  @brief Example for drawing Text using wxWidgets
27  @ingroup g_examples
28  @author MIP
29 */
30 #include <Gui/DrawTextWx.hh>
31 #include <wx/wx.h>
32 
33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 
36 
37 
38 using namespace BIAS;
39 using namespace std;
40 
41 /** \cond HIDDEN_SYMBOLS*/
42 class MyApp : public wxApp
43 {
44  virtual bool OnInit()
45  {
46  wxInitAllImageHandlers();
47 
48  unsigned width = 640, height = 480;
49  Image<unsigned char> img(width, height, 3);
51  img.FillImageWithXValue();
52  if (ImageIO::Save("source.mip", img)!=0){
53  cerr << "Error saving source image\n";
54  return false;
55  }
56  string text = "foobar 42";
57  unsigned pos_x = 10, pos_y = 10;
58  unsigned bb_text_width, bb_text_height;
59  if (DrawTextWx<unsigned char>::GetTextExtend(text, bb_text_width,
60  bb_text_height)!=DTWX_OK){
61  cerr << "Error getting text extend\n";
62  return false;
63  }
64  cout << "extend of text is "<<bb_text_width<<", "<<bb_text_height<<endl;
65 
66  if (DrawTextWx<unsigned char>::Text(img, text, pos_x, pos_y)!=DTWX_OK){
67  cerr << "Error drawing text\n";
68  return false;
69  }
70 
71  text += "(centered)";
72  pos_x = width/2;
73  pos_y = height/2;
74  ColourRGB<unsigned char> red(255, 0, 0);
75  ColourRGB<unsigned char> green(0, 255, 0);
80  unsigned point_size = 12;
81  if (DrawTextWx<unsigned char>::Text(img, text, pos_x, pos_y, red, green,
82  point_size, valign, halign)!=DTWX_OK){
83  cerr << "Error drawing text\n";
84  return false;
85  }
86 
87  if (ImageIO::Save("text.mip", img)!=0){
88  cerr << "Error saving destination image\n";
89  return false;
90  }
91 
92  return false;
93  }
94 };
95 /** \endcond */
96 IMPLEMENT_APP(MyApp)
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
void FillImageWithXValue()
fills image with value depending on x coordinate
Definition: Image.cpp:608
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
Writing a text in an bias image usig a wx device context This class uses wxDC and thus it can only be...
Definition: DrawTextWx.hh:45