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

Example for drawing Text using wxWidgets

Author
MIP
/* This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Vision N GmbH
Schauenburgerstr. 116
24118 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 ExampleDrawTextWx.cpp
@relates DrawTextWx
@brief Example for drawing Text using wxWidgets
@ingroup g_examples
@author MIP
*/
#include <Gui/DrawTextWx.hh>
#include <wx/wx.h>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
/** \cond HIDDEN_SYMBOLS*/
class MyApp : public wxApp
{
virtual bool OnInit()
{
wxInitAllImageHandlers();
unsigned width = 640, height = 480;
Image<unsigned char> img(width, height, 3);
if (ImageIO::Save("source.mip", img)!=0){
cerr << "Error saving source image\n";
return false;
}
string text = "foobar 42";
unsigned pos_x = 10, pos_y = 10;
unsigned bb_text_width, bb_text_height;
if (DrawTextWx<unsigned char>::GetTextExtend(text, bb_text_width,
bb_text_height)!=DTWX_OK){
cerr << "Error getting text extend\n";
return false;
}
cout << "extend of text is "<<bb_text_width<<", "<<bb_text_height<<endl;
if (DrawTextWx<unsigned char>::Text(img, text, pos_x, pos_y)!=DTWX_OK){
cerr << "Error drawing text\n";
return false;
}
text += "(centered)";
pos_x = width/2;
pos_y = height/2;
ColourRGB<unsigned char> red(255, 0, 0);
ColourRGB<unsigned char> green(0, 255, 0);
unsigned point_size = 12;
if (DrawTextWx<unsigned char>::Text(img, text, pos_x, pos_y, red, green,
point_size, valign, halign)!=DTWX_OK){
cerr << "Error drawing text\n";
return false;
}
if (ImageIO::Save("text.mip", img)!=0){
cerr << "Error saving destination image\n";
return false;
}
return false;
}
};
/** \endcond */
IMPLEMENT_APP(MyApp)