1 \chapter{Images and bitmaps
}\label{chapimages
}
2 \pagenumbering{arabic
}%
3 \setheader{{\it CHAPTER
\thechapter: IMAGES AND BITMAPS
}}{}{}{}{}{{\it CHAPTER
\thechapter: IMAGES AND BITMAPS
}}%
4 \setfooter{\thepage}{}{}{}{}{\thepage}%
6 \section{The basics of images and bitmaps
}
8 Both wxImage and wxBitmap represent what would commonly be referred as
9 a photo with a given number of pixels - in contrast to a drawing consisting
10 of a collection of lines, curves, circles, squares etc.
12 The difference between a wxImage and a wxBitmap is that wxImage is a
13 platform and screen independent representation of an image - every
14 pixel is always represented by three bytes, one for red, one for green
15 and one for blue, thus yielding the classical RGB acronym. Due to the
16 simplicity of wxImage, you will do all kinds of image manipulation
17 with this class, this includes loading images in various formats
18 such as GIF, TIFF or JPEG (these and some more are supported by wxWindows
19 without further work), analyizing the image in terms of colour usage etc
20 and applying filters to the image for higher-level manipulation, such
21 as blurring, sharpening etc.
23 The problem with wxImage is that you cannot draw it, i.e. its destiny
24 is to live its shadow life in memory, without ever being seen by man.
25 If you ever want to draw an image to screen, you have to convert it
26 to a wxBitmap first, typically, this will look like this:
29 wxImage image(
200,
200 );
30 wxBitmap bitmap( image.ConvertToBitmap() );
33 dc.DrawBitmap( bitmap );
36 Note, that such as image conversion is an extremely expensive operation
37 and you are very well advised to avoid having to call this routine
38 more than absolutely required. In practice, you should not do this
39 in a paint event handler, for instance.
41 There is one more thing you can do with a wxBitmap: you can draw into
42 it like you would do with a window. All you need to do is set up a
43 proper device context (DC) for it and ensure that you clean up the
44 DC correctly afterwards:
47 wxBitmap bitmap(
200,
200 );
50 dc.SelectObject( bitmap );
52 dc.SetPen( *wxBLACK_PEN );
53 dc.DrawLine(
0,
0,
199,
199 );
55 dc.SelectObject( wxNullBitmap );
58 \section{wxImage built-in features
}
60 You can save it, load it, get access to it, assign it a mask colour,
61 turn it around, mirror it.