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 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxIMAGE
\_TYPE\_PNG}}
51 Loads an image from an input stream.
53 \wxheading{Parameters
}
55 \docparam{width
}{Specifies the width of the image.
}
57 \docparam{height
}{Specifies the height of the image.
}
59 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
61 \docparam{stream
}{This refers to an input stream. Its meaning is determined by the
{\it type
} parameter. It is equal to loading from file except that you provide opened stream (file, HTTP or any other custom class).
}
63 \docparam{type
}{May be one of the following:
67 \twocolitem{{\bf \indexit{wxIMAGE
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
68 \twocolitem{{\bf \indexit{wxIMAGE
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
71 The validity of these flags depends on the platform and wxWindows configuration.
72 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file
73 and a PNG (portable network graphics) file is supported on all platforms that
78 \helpref{wxImage::LoadFile
}{wximageloadfile
}
80 \membersection{wxImage::
\destruct{wxImage
}}
82 \func{}{\destruct{wxImage
}}{\void}
86 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
88 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
90 Adds a handler to the end of the static list of format handlers.
92 \docparam{handler
}{A new image format handler object. There is usually only one instance
93 of a given handler class in an application session.
}
97 \helpref{wxImageHandler
}{wximagehandler
}
99 \membersection{wxImage::CleanUpHandlers
}
101 \func{static void
}{CleanUpHandlers
}{\void}
103 Deletes all image handlers.
105 This function is called by wxWindows on exit.
107 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
109 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
111 Converts the image to a platform-specific bitmap object. This has to be done
112 to actually display an image as you cannot draw an image directly on a window.
113 The resulting bitmap will use the colour depth of the current system which entails
114 that a (crude) colour reduction has to take place. Especially when converting
115 to
8-bit (or even less) bitmaps, the routine is slow and will reduce the
116 quality of the resulting bitmap. A proper set of colour reduction methods has
117 not yet been written.
119 \membersection{wxImage::Create
}\label{wximagecreate
}
121 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
123 Creates a fresh image.
125 \wxheading{Parameters
}
127 \docparam{width
}{The width of the image in pixels.
}
129 \docparam{height
}{The height of the image in pixels.
}
131 \wxheading{Return value
}
133 TRUE if the call succeeded, FALSE otherwise.
135 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
137 \func{bool
}{Destroy
}{\void}
139 Destroys the image data.
141 \membersection{wxImage::FindHandler
}
143 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
145 Finds the handler with the given name.
147 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
149 Finds the handler associated with the given extension and type.
151 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
153 Finds the handler associated with the given image type.
155 \docparam{name
}{The handler name.
}
157 \docparam{extension
}{The file extension, such as ``bmp".
}
159 \docparam{imageType
}{The image type, such as wxIMAGE
\_TYPE\_BMP.
}
161 \wxheading{Return value
}
163 A pointer to the handler if found, NULL otherwise.
167 \helpref{wxImageHandler
}{wximagehandler
}
169 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
171 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
173 Returns the blue intensity at the given coordinate.
175 \membersection{wxImage::GetData
}\label{wximagegetdata
}
177 \constfunc{unsigned char*
}{GetData
}{\void}
179 Returns the image data as an array. This is most often used when doing
180 direct image manipulation. The return value points to an array of
181 chararcters in RGBGBRGB... format.
183 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
185 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
187 Returns the green intensity at the given coordinate.
189 \membersection{wxImage::GetRed
}\label{wximagegetred
}
191 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
193 Returns the red intensity at the given coordinate.
195 \membersection{wxImage::GetHandlers
}
197 \func{static wxList\&
}{GetHandlers
}{\void}
199 Returns the static list of image format handlers.
203 \helpref{wxImageHandler
}{wximagehandler
}
205 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
207 \constfunc{int
}{GetHeight
}{\void}
209 Gets the height of the image in pixels.
211 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
213 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
215 Gets the blue value of the mask colour.
217 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
219 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
221 Gets the green value of the mask colour.
223 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
225 \constfunc{unsigned char
}{GetMaskRed
}{\void}
227 Gets the red value of the mask colour.
229 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
231 \constfunc{int
}{GetWidth
}{\void}
233 Gets the width of the image in pixels.
237 \helpref{wxImage::GetHeight
}{wximagegetheight
}
239 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
241 \constfunc{bool
}{HasMask
}{\void}
243 Returns TRUE if there is a mask active, FALSE otherwise.
245 \membersection{wxImage::InitStandardHandlers
}
247 \func{static void
}{InitStandardHandlers
}{\void}
249 Adds the standard image format handlers, which, depending on wxWindows
250 configuration, can be handlers for Windows BMP (loading) and PNG
251 (loading and saving) file formats.
253 This function is called by wxWindows on startup.
257 \helpref{wxImageHandler
}{wximagehandler
}
259 \membersection{wxImage::InsertHandler
}
261 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
263 Adds a handler at the start of the static list of format handlers.
265 \docparam{handler
}{A new image format handler object. There is usually only one instance
266 of a given handler class in an application session.
}
270 \helpref{wxImageHandler
}{wximagehandler
}
272 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
274 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
276 Loads an image from a file.
278 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
280 Loads an image from an input stream.
282 \wxheading{Parameters
}
284 \docparam{name
}{A filename.
285 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
287 \docparam{stream
}{An input stream.
288 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
290 \docparam{type
}{One of the following values:
294 \twocolitem{{\bf wxIMAGE
\_TYPE\_BMP}}{Load a Windows image file.
}
295 \twocolitem{{\bf wxIMAGE
\_TYPE\_PNG}}{Load a PNG image file.
}
298 The validity of these flags depends on the platform and wxWindows configuration.
}
300 \wxheading{Return value
}
302 TRUE if the operation succeeded, FALSE otherwise.
306 \helpref{wxImage::SaveFile
}{wximagesavefile
}
308 \membersection{wxImage::Ok
}\label{wximageok
}
310 \constfunc{bool
}{Ok
}{\void}
312 Returns TRUE if image data is present.
314 \membersection{wxImage::RemoveHandler
}
316 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
318 Finds the handler with the given name, and removes it. The handler
321 \docparam{name
}{The handler name.
}
323 \wxheading{Return value
}
325 TRUE if the handler was found and removed, FALSE otherwise.
329 \helpref{wxImageHandler
}{wximagehandler
}
331 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
333 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
335 Saves a image in the named file.
337 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
339 Saves a image in the given stream.
341 \wxheading{Parameters
}
343 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
345 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
347 \docparam{type
}{Currently only one type can be used:
351 \twocolitem{{\bf wxIMAGE
\_TYPE\_PNG}}{Save a PNG image file.
}
354 The validity of these flags depends on the platform and wxWindows configuration
355 as well as user-added handlers.
}
357 \wxheading{Return value
}
359 TRUE if the operation succeeded, FALSE otherwise.
363 Depending on how wxWindows has been configured, not all formats may be available.
367 \helpref{wxImage::LoadFile
}{wximageloadfile
}
369 \membersection{wxImage::Scale
}\label{wximagescale
}
371 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
373 Returns a scaled version of the image. This is also useful for
374 scaling bitmaps in general as the only other way to scale bitmaps
375 is do blit a wxMemoryDC into another wxMemoryDC. Windows can such scaling
376 itself, but on GTK scaling bitmaps is done using this routine
379 \membersection{wxImage::SetData
}\label{wximagesetdata
}
381 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
383 Sets the image data without performing checks. The data given must have
384 the size (width*height*
3) or results will be unexpected. Don't use this
385 method if you aren't sure you know what you are doing.
387 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
389 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
391 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
393 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
395 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
397 Sets the mask colour for this image.
399 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
401 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
403 Sets the pixel at the given coordinate. This routine performs bounds-checks
404 for the coordinate so it can be considered a safe way to manipulate the
405 data, but in some cases this might be too slow so that the data will have to
406 be set directly. In that case you have to get that data by calling GetData().
408 \membersection{wxImage::operator $=$
}
410 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
412 Assignment operator. This operator does not copy any data, but instead
413 passes a pointer to the data in
{\it image
} and increments a reference
414 counter. It is a fast operation.
416 \wxheading{Parameters
}
418 \docparam{image
}{Image to assign.
}
420 \wxheading{Return value
}
422 Returns 'this' object.
424 \membersection{wxImage::operator $==$
}
426 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
428 Equality operator. This operator tests whether the internal data pointers are
431 \wxheading{Parameters
}
433 \docparam{image
}{Image to compare with 'this'
}
435 \wxheading{Return value
}
437 Returns TRUE if the images were effectively equal, FALSE otherwise.
439 \membersection{wxImage::operator $!=$
}
441 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
443 Inequality operator. This operator tests whether the internal data pointers are
444 unequal (a fast test).
446 \wxheading{Parameters
}
448 \docparam{image
}{Image to compare with 'this'
}
450 \wxheading{Return value
}
452 Returns TRUE if the images were unequal, FALSE otherwise.
454 \section{\class{wxImageHandler
}}\label{wximagehandler
}
456 This is the base class for implementing image file loading/saving, and image creation from data.
457 It is used within wxImage and is not normally seen by the application.
459 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
460 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
461 application initialisation.
463 \wxheading{Derived from
}
465 \helpref{wxObject
}{wxobject
}
469 \helpref{wxImage
}{wximage
}
471 \latexignore{\rtfignore{\wxheading{Members
}}}
473 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
475 \func{}{wxImageHandler
}{\void}
477 Default constructor. In your own default constructor, initialise the members
478 m
\_name, m
\_extension and m
\_type.
480 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
482 \func{}{\destruct{wxImageHandler
}}{\void}
484 Destroys the wxImageHandler object.
486 \membersection{wxImageHandler::GetName
}
488 \constfunc{wxString
}{GetName
}{\void}
490 Gets the name of this handler.
492 \membersection{wxImageHandler::GetExtension
}
494 \constfunc{wxString
}{GetExtension
}{\void}
496 Gets the file extension associated with this handler.
498 \membersection{wxImageHandler::GetType
}
500 \constfunc{long
}{GetType
}{\void}
502 Gets the image type associated with this handler.
504 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
506 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
508 Loads a image from a stream, putting the resulting data into
{\it image
}.
510 \wxheading{Parameters
}
512 \docparam{image
}{The image object which is to be affected by this operation.
}
514 \docparam{stream
}{Opened input stream.
515 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
517 \wxheading{Return value
}
519 TRUE if the operation succeeded, FALSE otherwise.
523 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
524 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
525 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
527 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
529 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
531 Saves a image in the output stream.
533 \wxheading{Parameters
}
535 \docparam{image
}{The image object which is to be affected by this operation.
}
537 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
539 \wxheading{Return value
}
541 TRUE if the operation succeeded, FALSE otherwise.
545 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
546 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
547 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
549 \membersection{wxImageHandler::SetName
}
551 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
553 Sets the handler name.
555 \wxheading{Parameters
}
557 \docparam{name
}{Handler name.
}
559 \membersection{wxImageHandler::SetExtension
}
561 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
563 Sets the handler extension.
565 \wxheading{Parameters
}
567 \docparam{extension
}{Handler extension.
}
569 \membersection{wxImageHandler::SetType
}
571 \func{void
}{SetType
}{\param{long
}{type
}}
573 Sets the handler type.
575 \wxheading{Parameters
}
577 \docparam{name
}{Handler type.
}