1 \section{\class{wxImage
}}\label{wximage
}
3 This class encapsulates a platform-independent image. An image can be created
4 from data, or using the constructor taking a wxBitmap object. An image
5 can be loaded from a file in a variety of formats, and is extensible to new formats
6 via image format handlers. Functions are available to set and get image bits, so
7 it can be used for basic image manipulation.
9 A wxImage cannot (currently) be drawn directly to a wxDC. Instead, a platform-specific
10 wxBitmap object must be created from it, and that bitmap drawn on the wxDC, using
13 This class is currently only available under GTK and Windows.
15 \wxheading{Derived from
}
17 \helpref{wxObject
}{wxobject
}
21 \helpref{wxBitmap
}{wxbitmap
}
23 \latexignore{\rtfignore{\wxheading{Members
}}}
25 \membersection{wxImage::wxImage
}\label{wximageconstr
}
27 \func{}{wxImage
}{\void}
31 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
35 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
37 Constructs an image from a platform-dependent bitmap. This preserves
38 mask information so that bitmaps and images can be converted back
39 and forth without loss in that respect.
41 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
43 Creates an image with the given width and height.
45 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxIMAGE
\_TYPE\_PNG}}
47 Loads an image from a file.
49 \wxheading{Parameters
}
51 \docparam{width
}{Specifies the width of the image.
}
53 \docparam{height
}{Specifies the height of the image.
}
55 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
57 \docparam{type
}{May be one of the following:
61 \twocolitem{{\bf \indexit{wxIMAGE
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
62 \twocolitem{{\bf \indexit{wxIMAGE
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
65 The validity of these flags depends on the platform and wxWindows configuration.
66 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file
67 and a PNG (portable network graphics) file is supported on all platforms that
72 \helpref{wxImage::LoadFile
}{wximageloadfile
}
74 \membersection{wxImage::
\destruct{wxImage
}}
76 \func{}{\destruct{wxImage
}}{\void}
80 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
82 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
84 Adds a handler to the end of the static list of format handlers.
86 \docparam{handler
}{A new image format handler object. There is usually only one instance
87 of a given handler class in an application session.
}
91 \helpref{wxImageHandler
}{wximagehandler
}
93 \membersection{wxImage::CleanUpHandlers
}
95 \func{static void
}{CleanUpHandlers
}{\void}
97 Deletes all image handlers.
99 This function is called by wxWindows on exit.
101 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
103 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
105 Converts the image to a platform-specific bitmap object. This has to be done
106 to actually display an image as you cannot draw an image directly on a window.
107 The resulting bitmap will use the colour depth of the current system which entails
108 that a (crude) colour reduction has to take place. Especially when converting
109 to
8-bit (or even less) bitmaps, the routine is slow and will reduce the
110 quality of the resulting bitmap. A proper set of colour reduction methods has
111 not yet been written.
113 \membersection{wxImage::Create
}\label{wximagecreate
}
115 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
117 Creates a fresh image.
119 \wxheading{Parameters
}
121 \docparam{width
}{The width of the image in pixels.
}
123 \docparam{height
}{The height of the image in pixels.
}
125 \wxheading{Return value
}
127 TRUE if the call succeeded, FALSE otherwise.
129 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
131 \func{bool
}{Destroy
}{\void}
133 Destroys the image data.
135 \membersection{wxImage::FindHandler
}
137 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
139 Finds the handler with the given name.
141 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
143 Finds the handler associated with the given extension and type.
145 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
147 Finds the handler associated with the given image type.
149 \docparam{name
}{The handler name.
}
151 \docparam{extension
}{The file extension, such as ``bmp".
}
153 \docparam{imageType
}{The image type, such as wxIMAGE
\_TYPE\_BMP.
}
155 \wxheading{Return value
}
157 A pointer to the handler if found, NULL otherwise.
161 \helpref{wxImageHandler
}{wximagehandler
}
163 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
165 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
167 Returns the blue intensity at the given coordinate.
169 \membersection{wxImage::GetData
}\label{wximagegetdata
}
171 \constfunc{unsigned char*
}{GetData
}{\void}
173 Returns the image data as an array. This is most often used when doing
174 direct image manipulation. The return value points to an array of
175 chararcters in RGBGBRGB... format.
177 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
179 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
181 Returns the green intensity at the given coordinate.
183 \membersection{wxImage::GetRed
}\label{wximagegetred
}
185 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
187 Returns the red intensity at the given coordinate.
189 \membersection{wxImage::GetHandlers
}
191 \func{static wxList\&
}{GetHandlers
}{\void}
193 Returns the static list of image format handlers.
197 \helpref{wxImageHandler
}{wximagehandler
}
199 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
201 \constfunc{int
}{GetHeight
}{\void}
203 Gets the height of the image in pixels.
205 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
207 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
209 Gets the blue value of the mask colour.
211 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
213 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
215 Gets the green value of the mask colour.
217 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
219 \constfunc{unsigned char
}{GetMaskRed
}{\void}
221 Gets the red value of the mask colour.
223 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
225 \constfunc{int
}{GetWidth
}{\void}
227 Gets the width of the image in pixels.
231 \helpref{wxImage::GetHeight
}{wximagegetheight
}
233 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
235 \constfunc{bool
}{HasMask
}{\void}
237 Returns TRUE if there is a mask active, FALSE otherwise.
239 \membersection{wxImage::InitStandardHandlers
}
241 \func{static void
}{InitStandardHandlers
}{\void}
243 Adds the standard image format handlers, which, depending on wxWindows
244 configuration, can be handlers for Windows BMP (loading) and PNG
245 (loading and saving) file formats.
247 This function is called by wxWindows on startup.
251 \helpref{wxImageHandler
}{wximagehandler
}
253 \membersection{wxImage::InsertHandler
}
255 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
257 Adds a handler at the start of the static list of format handlers.
259 \docparam{handler
}{A new image format handler object. There is usually only one instance
260 of a given handler class in an application session.
}
264 \helpref{wxImageHandler
}{wximagehandler
}
266 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
268 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
270 Loads an image from a file.
272 \wxheading{Parameters
}
274 \docparam{name
}{A filename.
275 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
277 \docparam{type
}{One of the following values:
281 \twocolitem{{\bf wxIMAGE
\_TYPE\_BMP}}{Load a Windows image file.
}
282 \twocolitem{{\bf wxIMAGE
\_TYPE\_PNG}}{Load a PNG image file.
}
285 The validity of these flags depends on the platform and wxWindows configuration.
}
287 \wxheading{Return value
}
289 TRUE if the operation succeeded, FALSE otherwise.
293 \helpref{wxImage::SaveFile
}{wximagesavefile
}
295 \membersection{wxImage::Ok
}\label{wximageok
}
297 \constfunc{bool
}{Ok
}{\void}
299 Returns TRUE if image data is present.
301 \membersection{wxImage::RemoveHandler
}
303 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
305 Finds the handler with the given name, and removes it. The handler
308 \docparam{name
}{The handler name.
}
310 \wxheading{Return value
}
312 TRUE if the handler was found and removed, FALSE otherwise.
316 \helpref{wxImageHandler
}{wximagehandler
}
318 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
320 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
322 Saves a image in the named file.
324 \wxheading{Parameters
}
326 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
328 \docparam{type
}{Currently only one type can be used:
332 \twocolitem{{\bf wxIMAGE
\_TYPE\_PNG}}{Save a PNG image file.
}
335 The validity of these flags depends on the platform and wxWindows configuration
336 as well as user-added handlers.
}
338 \wxheading{Return value
}
340 TRUE if the operation succeeded, FALSE otherwise.
344 Depending on how wxWindows has been configured, not all formats may be available.
348 \helpref{wxImage::LoadFile
}{wximageloadfile
}
350 \membersection{wxImage::Scale
}\label{wximagescale
}
352 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
354 Returns a scaled version of the image. This is also useful for
355 scaling bitmaps in general as the only other way to scale bitmaps
356 is do blit a wxMemoryDC into another wxMemoryDC. Windows can such scaling
357 itself, but on GTK scaling bitmaps is done using this routine
360 \membersection{wxImage::SetData
}\label{wximagesetdata
}
362 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
364 Sets the image data without performing checks. The data given must have
365 the size (width*height*
3) or results will be unexpected. Don't use this
366 method if you aren't sure you know what you are doing.
368 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
370 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
372 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
374 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
376 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
378 Sets the mask colour for this image.
380 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
382 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
384 Sets the pixel at the given coordinate. This routine performs bounds-checks
385 for the coordinate so it can be considered a safe way to manipulate the
386 data, but in some cases this might be too slow so that the data will have to
387 be set directly. In that case you have to get that data by calling GetData().
389 \membersection{wxImage::operator $=$
}
391 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
393 Assignment operator. This operator does not copy any data, but instead
394 passes a pointer to the data in
{\it image
} and increments a reference
395 counter. It is a fast operation.
397 \wxheading{Parameters
}
399 \docparam{image
}{Image to assign.
}
401 \wxheading{Return value
}
403 Returns 'this' object.
405 \membersection{wxImage::operator $==$
}
407 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
409 Equality operator. This operator tests whether the internal data pointers are
412 \wxheading{Parameters
}
414 \docparam{image
}{Image to compare with 'this'
}
416 \wxheading{Return value
}
418 Returns TRUE if the images were effectively equal, FALSE otherwise.
420 \membersection{wxImage::operator $!=$
}
422 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
424 Inequality operator. This operator tests whether the internal data pointers are
425 unequal (a fast test).
427 \wxheading{Parameters
}
429 \docparam{image
}{Image to compare with 'this'
}
431 \wxheading{Return value
}
433 Returns TRUE if the images were unequal, FALSE otherwise.
435 \section{\class{wxImageHandler
}}\label{wximagehandler
}
437 This is the base class for implementing image file loading/saving, and image creation from data.
438 It is used within wxImage and is not normally seen by the application.
440 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
441 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
442 application initialisation.
444 \wxheading{Derived from
}
446 \helpref{wxObject
}{wxobject
}
450 \helpref{wxImage
}{wximage
}
452 \latexignore{\rtfignore{\wxheading{Members
}}}
454 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
456 \func{}{wxImageHandler
}{\void}
458 Default constructor. In your own default constructor, initialise the members
459 m
\_name, m
\_extension and m
\_type.
461 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
463 \func{}{\destruct{wxImageHandler
}}{\void}
465 Destroys the wxImageHandler object.
467 \membersection{wxImageHandler::GetName
}
469 \constfunc{wxString
}{GetName
}{\void}
471 Gets the name of this handler.
473 \membersection{wxImageHandler::GetExtension
}
475 \constfunc{wxString
}{GetExtension
}{\void}
477 Gets the file extension associated with this handler.
479 \membersection{wxImageHandler::GetType
}
481 \constfunc{long
}{GetType
}{\void}
483 Gets the image type associated with this handler.
485 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
487 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{const wxString\&
}{ name
}}
489 Loads a image from a file or resource, putting the resulting data into
{\it image
}.
491 \wxheading{Parameters
}
493 \docparam{image
}{The image object which is to be affected by this operation.
}
495 \docparam{name
}{Either a filename or a Windows resource name.
496 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
498 \wxheading{Return value
}
500 TRUE if the operation succeeded, FALSE otherwise.
504 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
505 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
506 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
508 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
510 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{const wxString\&
}{name
}}
512 Saves a image in the named file.
514 \wxheading{Parameters
}
516 \docparam{image
}{The image object which is to be affected by this operation.
}
518 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
520 \wxheading{Return value
}
522 TRUE if the operation succeeded, FALSE otherwise.
526 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
527 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
528 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
530 \membersection{wxImageHandler::SetName
}
532 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
534 Sets the handler name.
536 \wxheading{Parameters
}
538 \docparam{name
}{Handler name.
}
540 \membersection{wxImageHandler::SetExtension
}
542 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
544 Sets the handler extension.
546 \wxheading{Parameters
}
548 \docparam{extension
}{Handler extension.
}
550 \membersection{wxImageHandler::SetType
}
552 \func{void
}{SetType
}{\param{long
}{type
}}
554 Sets the handler type.
556 \wxheading{Parameters
}
558 \docparam{name
}{Handler type.
}