]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/book/chap_images.tex
Updated section on XRC-writing tools
[wxWidgets.git] / docs / latex / book / chap_images.tex
CommitLineData
397f14ce
JS
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
e80658da
RR
6\section{The basics of images and bitmaps}
7
8Both wxImage and wxBitmap represent what would commonly be referred as
9a photo with a given number of pixels - in contrast to a drawing consisting
10of a collection of lines, curves, circles, squares etc.
11
12The difference between a wxImage and a wxBitmap is that wxImage is a
13platform and screen independent representation of an image - every
14pixel is always represented by three bytes, one for red, one for green
15and one for blue, thus yielding the classical RGB acronym. Due to the
16simplicity of wxImage, you will do all kinds of image manipulation
17with this class, this includes loading images in various formats
18such as GIF, TIFF or JPEG (these and some more are supported by wxWindows
2edb0bde 19without further work), analyzing the image in terms of colour usage etc
e80658da
RR
20and applying filters to the image for higher-level manipulation, such
21as blurring, sharpening etc.
22
23The problem with wxImage is that you cannot draw it, i.e. its destiny
24is to live its shadow life in memory, without ever being seen by man.
25If you ever want to draw an image to screen, you have to convert it
26to 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
36Note, that such as image conversion is an extremely expensive operation
37and you are very well advised to avoid having to call this routine
38more than absolutely required. In practice, you should not do this
39in a paint event handler, for instance.
40
41There is one more thing you can do with a wxBitmap: you can draw into
42it like you would do with a window. All you need to do is set up a
43proper device context (DC) for it and ensure that you clean up the
44DC 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
60You can save it, load it, get access to it, assign it a mask colour,
61turn it around, mirror it.
397f14ce 62