]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/book/chap_images.tex
documented that SetSelection(-1) removes the selection
[wxWidgets.git] / docs / latex / book / chap_images.tex
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}%
5
6 \section{The basics of images and bitmaps}
7
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.
11
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), analyzing 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.
22
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:
27
28 \begin{verbatim}
29 wxImage image( 200, 200 );
30 wxBitmap bitmap( image.ConvertToBitmap() );
31
32 wxClientDC dc( this )
33 dc.DrawBitmap( bitmap );
34 \end{verbatim}
35
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.
40
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:
45
46 \begin{verbatim}
47 wxBitmap bitmap( 200, 200 );
48
49 wxMemoryDC dc;
50 dc.SelectObject( bitmap );
51
52 dc.SetPen( *wxBLACK_PEN );
53 dc.DrawLine( 0, 0, 199, 199 );
54
55 dc.SelectObject( wxNullBitmap );
56 \end{verbatim}
57
58 \section{wxImage built-in features}
59
60 You can save it, load it, get access to it, assign it a mask colour,
61 turn it around, mirror it.
62