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 \wxheading{Derived from
}
15 \helpref{wxObject
}{wxobject
}
17 \wxheading{Include files
}
23 \helpref{wxBitmap
}{wxbitmap
}
25 \latexignore{\rtfignore{\wxheading{Members
}}}
27 \membersection{wxImage::wxImage
}\label{wximageconstr
}
29 \func{}{wxImage
}{\void}
33 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
37 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
39 Constructs an image from a platform-dependent bitmap. This preserves
40 mask information so that bitmaps and images can be converted back
41 and forth without loss in that respect.
43 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
45 Creates an image with the given width and height.
47 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
49 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
51 Loads an image from a file.
53 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
55 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
57 Loads an image from an input stream.
59 \wxheading{Parameters
}
61 \docparam{width
}{Specifies the width of the image.
}
63 \docparam{height
}{Specifies the height of the image.
}
65 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
67 \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).
}
69 \docparam{type
}{May be one of the following:
73 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
74 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
75 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_JPEG}}}{Load a JPEG bitmap file.
}
78 The validity of these flags depends on the platform and wxWindows configuration.
79 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
80 a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
83 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
85 Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
86 initialization in order to work with JPEGs.
90 \helpref{wxImage::LoadFile
}{wximageloadfile
}
92 \pythonnote{Constructors supported by wxPython are:
\par
93 \indented{2cm
}{\begin{twocollist
}
94 \twocolitem{\bf{wxImage(name, flag)
}}{Loads an image from a file
}
95 \twocolitem{\bf{wxNullImage()
}}{Create a null image (has no size or
97 \twocolitem{\bf{wxEmptyImage(width, height)
}}{Creates an empty image
99 \twocolitem{\bf{wxImageFromMime(name, mimetype
}}{Creates an image from
100 the given file of the given mimetype
}
101 \twocolitem{\bf{wxImageFromBitmap(bitmap)
}}{Creates an image from a
102 platform-dependent bitmap
}
106 \membersection{wxImage::
\destruct{wxImage
}}
108 \func{}{\destruct{wxImage
}}{\void}
112 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
114 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
116 Adds a handler to the end of the static list of format handlers.
118 \docparam{handler
}{A new image format handler object. There is usually only one instance
119 of a given handler class in an application session.
}
123 \helpref{wxImageHandler
}{wximagehandler
}
125 \pythonnote{In wxPython this static method is named
\tt{wxImage_AddHandler
}.
}
126 \membersection{wxImage::CleanUpHandlers
}
128 \func{static void
}{CleanUpHandlers
}{\void}
130 Deletes all image handlers.
132 This function is called by wxWindows on exit.
134 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
136 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
138 Converts the image to a platform-specific bitmap object. This has to be done
139 to actually display an image as you cannot draw an image directly on a window.
140 The resulting bitmap will use the colour depth of the current system which entails
141 that a (crude) colour reduction has to take place. When in
8-bit mode, this
142 routine will use a
color cube created on program start-up to look up colors.
143 Still, the image quality won't be perfect for photo images.
145 \membersection{wxImage::Create
}\label{wximagecreate
}
147 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
149 Creates a fresh image.
151 \wxheading{Parameters
}
153 \docparam{width
}{The width of the image in pixels.
}
155 \docparam{height
}{The height of the image in pixels.
}
157 \wxheading{Return value
}
159 TRUE if the call succeeded, FALSE otherwise.
161 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
163 \func{bool
}{Destroy
}{\void}
165 Destroys the image data.
167 \membersection{wxImage::FindHandler
}
169 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
171 Finds the handler with the given name.
173 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
175 Finds the handler associated with the given extension and type.
177 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
179 Finds the handler associated with the given image type.
181 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
183 Finds the handler associated with the given MIME type.
185 \docparam{name
}{The handler name.
}
187 \docparam{extension
}{The file extension, such as ``bmp".
}
189 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
191 \docparam{mimetype
}{MIME type.
}
193 \wxheading{Return value
}
195 A pointer to the handler if found, NULL otherwise.
199 \helpref{wxImageHandler
}{wximagehandler
}
201 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
203 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
205 Returns the blue intensity at the given coordinate.
207 \membersection{wxImage::GetData
}\label{wximagegetdata
}
209 \constfunc{unsigned char*
}{GetData
}{\void}
211 Returns the image data as an array. This is most often used when doing
212 direct image manipulation. The return value points to an array of
213 chararcters in RGBGBRGB... format.
215 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
217 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
219 Returns the green intensity at the given coordinate.
221 \membersection{wxImage::GetRed
}\label{wximagegetred
}
223 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
225 Returns the red intensity at the given coordinate.
227 \membersection{wxImage::GetHandlers
}
229 \func{static wxList\&
}{GetHandlers
}{\void}
231 Returns the static list of image format handlers.
235 \helpref{wxImageHandler
}{wximagehandler
}
237 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
239 \constfunc{int
}{GetHeight
}{\void}
241 Gets the height of the image in pixels.
243 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
245 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
247 Gets the blue value of the mask colour.
249 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
251 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
253 Gets the green value of the mask colour.
255 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
257 \constfunc{unsigned char
}{GetMaskRed
}{\void}
259 Gets the red value of the mask colour.
261 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
263 \constfunc{int
}{GetWidth
}{\void}
265 Gets the width of the image in pixels.
269 \helpref{wxImage::GetHeight
}{wximagegetheight
}
271 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
273 \constfunc{bool
}{HasMask
}{\void}
275 Returns TRUE if there is a mask active, FALSE otherwise.
277 \membersection{wxImage::InitStandardHandlers
}
279 \func{static void
}{InitStandardHandlers
}{\void}
281 Adds the standard image format handlers, which, depending on wxWindows
282 configuration, can be handlers for Windows BMP (loading), PNG
283 (loading and saving) and JPEG (loading and saving) file formats.
285 This function is called by wxWindows on startup.
289 \helpref{wxImageHandler
}{wximagehandler
}
291 \membersection{wxImage::InsertHandler
}
293 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
295 Adds a handler at the start of the static list of format handlers.
297 \docparam{handler
}{A new image format handler object. There is usually only one instance
298 of a given handler class in an application session.
}
302 \helpref{wxImageHandler
}{wximagehandler
}
304 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
306 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
308 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
}}
310 Loads an image from a file.
312 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
314 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
}}
316 Loads an image from an input stream.
318 \wxheading{Parameters
}
320 \docparam{name
}{A filename.
321 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
323 \docparam{stream
}{An input stream.
324 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
326 \docparam{type
}{One of the following values:
330 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
331 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
332 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
335 The validity of these flags depends on the platform and wxWindows configuration.
}
337 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
339 \wxheading{Return value
}
341 TRUE if the operation succeeded, FALSE otherwise.
345 \helpref{wxImage::SaveFile
}{wximagesavefile
}
347 \pythonnote{In place of a single overloaded method name, wxPython
348 implements the following methods:
\par
349 \indented{2cm
}{\begin{twocollist
}
350 \twocolitem{\bf{LoadFile(filename, type)
}}{Loads an image of the given
352 \twocolitem{\bf{LoadMimeFile(filename, mimetype)
}}{Loads an image of the given
353 mimetype from a file
}
358 \membersection{wxImage::Ok
}\label{wximageok
}
360 \constfunc{bool
}{Ok
}{\void}
362 Returns TRUE if image data is present.
364 \membersection{wxImage::RemoveHandler
}
366 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
368 Finds the handler with the given name, and removes it. The handler
371 \docparam{name
}{The handler name.
}
373 \wxheading{Return value
}
375 TRUE if the handler was found and removed, FALSE otherwise.
379 \helpref{wxImageHandler
}{wximagehandler
}
381 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
383 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
385 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
387 Saves a image in the named file.
389 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
391 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
393 Saves a image in the given stream.
395 \wxheading{Parameters
}
397 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
399 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
401 \docparam{type
}{Currently two types can be used:
405 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
406 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
409 The validity of these flags depends on the platform and wxWindows configuration
410 as well as user-added handlers.
}
412 \docparam{mimetype
}{MIME type.
}
414 \wxheading{Return value
}
416 TRUE if the operation succeeded, FALSE otherwise.
420 Depending on how wxWindows has been configured, not all formats may be available.
424 \helpref{wxImage::LoadFile
}{wximageloadfile
}
426 \pythonnote{In place of a single overloaded method name, wxPython
427 implements the following methods:
\par
428 \indented{2cm
}{\begin{twocollist
}
429 \twocolitem{\bf{SaveFile(filename, type)
}}{Saves the image using the given
430 type to the named file
}
431 \twocolitem{\bf{SaveMimeFile(filename, mimetype)
}}{Saves the image using the given
432 mimetype to the named file
}
436 \membersection{wxImage::Scale
}\label{wximagescale
}
438 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
440 Returns a scaled version of the image. This is also useful for
441 scaling bitmaps in general as the only other way to scale bitmaps
442 is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such
443 scaling itself but in the GTK port, scaling bitmaps is done using
444 this routine internally.
446 \membersection{wxImage::SetData
}\label{wximagesetdata
}
448 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
450 Sets the image data without performing checks. The data given must have
451 the size (width*height*
3) or results will be unexpected. Don't use this
452 method if you aren't sure you know what you are doing.
454 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
456 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
458 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
460 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
462 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
464 Sets the mask colour for this image (and tells the image to use the mask).
466 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
468 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
470 Sets the pixel at the given coordinate. This routine performs bounds-checks
471 for the coordinate so it can be considered a safe way to manipulate the
472 data, but in some cases this might be too slow so that the data will have to
473 be set directly. In that case you have to get that data by calling GetData().
475 \membersection{wxImage::operator $=$
}
477 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
479 Assignment operator. This operator does not copy any data, but instead
480 passes a pointer to the data in
{\it image
} and increments a reference
481 counter. It is a fast operation.
483 \wxheading{Parameters
}
485 \docparam{image
}{Image to assign.
}
487 \wxheading{Return value
}
489 Returns 'this' object.
491 \membersection{wxImage::operator $==$
}
493 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
495 Equality operator. This operator tests whether the internal data pointers are
498 \wxheading{Parameters
}
500 \docparam{image
}{Image to compare with 'this'
}
502 \wxheading{Return value
}
504 Returns TRUE if the images were effectively equal, FALSE otherwise.
506 \membersection{wxImage::operator $!=$
}
508 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
510 Inequality operator. This operator tests whether the internal data pointers are
511 unequal (a fast test).
513 \wxheading{Parameters
}
515 \docparam{image
}{Image to compare with 'this'
}
517 \wxheading{Return value
}
519 Returns TRUE if the images were unequal, FALSE otherwise.
521 \section{\class{wxImageHandler
}}\label{wximagehandler
}
523 This is the base class for implementing image file loading/saving, and image creation from data.
524 It is used within wxImage and is not normally seen by the application.
526 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
527 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
528 application initialisation.
530 \wxheading{Note (Legal Issue)
}
532 This software is based in part on the work of the Independent JPEG Group.
534 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
537 \wxheading{Derived from
}
539 \helpref{wxObject
}{wxobject
}
541 \wxheading{Include files
}
547 \helpref{wxImage
}{wximage
}
549 \latexignore{\rtfignore{\wxheading{Members
}}}
551 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
553 \func{}{wxImageHandler
}{\void}
555 Default constructor. In your own default constructor, initialise the members
556 m
\_name, m
\_extension and m
\_type.
558 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
560 \func{}{\destruct{wxImageHandler
}}{\void}
562 Destroys the wxImageHandler object.
564 \membersection{wxImageHandler::GetName
}
566 \constfunc{wxString
}{GetName
}{\void}
568 Gets the name of this handler.
570 \membersection{wxImageHandler::GetExtension
}
572 \constfunc{wxString
}{GetExtension
}{\void}
574 Gets the file extension associated with this handler.
576 \membersection{wxImageHandler::GetType
}
578 \constfunc{long
}{GetType
}{\void}
580 Gets the image type associated with this handler.
582 \membersection{wxImageHandler::GetMimeType
}
584 \constfunc{wxString
}{GetMimeType
}{\void}
586 Gets the MIME type associated with this handler.
588 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
590 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
592 Loads a image from a stream, putting the resulting data into
{\it image
}.
594 \wxheading{Parameters
}
596 \docparam{image
}{The image object which is to be affected by this operation.
}
598 \docparam{stream
}{Opened input stream.
599 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
601 \wxheading{Return value
}
603 TRUE if the operation succeeded, FALSE otherwise.
607 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
608 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
609 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
611 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
613 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
615 Saves a image in the output stream.
617 \wxheading{Parameters
}
619 \docparam{image
}{The image object which is to be affected by this operation.
}
621 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
623 \wxheading{Return value
}
625 TRUE if the operation succeeded, FALSE otherwise.
629 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
630 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
631 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
633 \membersection{wxImageHandler::SetName
}
635 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
637 Sets the handler name.
639 \wxheading{Parameters
}
641 \docparam{name
}{Handler name.
}
643 \membersection{wxImageHandler::SetExtension
}
645 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
647 Sets the handler extension.
649 \wxheading{Parameters
}
651 \docparam{extension
}{Handler extension.
}
653 \membersection{wxImageHandler::SetType
}
655 \func{void
}{SetType
}{\param{long
}{type
}}
657 Sets the handler type.
659 \wxheading{Parameters
}
661 \docparam{name
}{Handler type.
}
664 \membersection{wxImageHandler::SetMimeType
}
666 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
668 Sets the handler MIME type.
670 \wxheading{Parameters
}
672 \docparam{mimename
}{Handler MIME type.
}