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
}
24 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
26 \latexignore{\rtfignore{\wxheading{Members
}}}
28 \membersection{wxImage::wxImage
}\label{wximageconstr
}
30 \func{}{wxImage
}{\void}
34 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
38 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
40 Constructs an image from a platform-dependent bitmap. This preserves
41 mask information so that bitmaps and images can be converted back
42 and forth without loss in that respect.
44 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
46 Creates an image with the given width and height.
48 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
50 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
52 Loads an image from a file.
54 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
56 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
58 Loads an image from an input stream.
60 \wxheading{Parameters
}
62 \docparam{width
}{Specifies the width of the image.
}
64 \docparam{height
}{Specifies the height of the image.
}
66 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
68 \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).
}
70 \docparam{type
}{May be one of the following:
74 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
75 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
76 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_JPEG}}}{Load a JPEG bitmap file.
}
77 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_GIF}}}{Load a GIF bitmap file.
}
78 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PCX}}}{Load a PCX bitmap file.
}
79 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNM}}}{Load a PNM bitmap file.
}
82 The validity of these flags depends on the platform and wxWindows configuration.
83 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
84 a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
87 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
89 Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
90 initialization in order to work with JPEGs.
94 \helpref{wxImage::LoadFile
}{wximageloadfile
}
96 \pythonnote{Constructors supported by wxPython are:
\par
97 \indented{2cm
}{\begin{twocollist
}
98 \twocolitem{\bf{wxImage(name, flag)
}}{Loads an image from a file
}
99 \twocolitem{\bf{wxNullImage()
}}{Create a null image (has no size or
101 \twocolitem{\bf{wxEmptyImage(width, height)
}}{Creates an empty image
103 \twocolitem{\bf{wxImageFromMime(name, mimetype
}}{Creates an image from
104 the given file of the given mimetype
}
105 \twocolitem{\bf{wxImageFromBitmap(bitmap)
}}{Creates an image from a
106 platform-dependent bitmap
}
110 \membersection{wxImage::
\destruct{wxImage
}}
112 \func{}{\destruct{wxImage
}}{\void}
116 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
118 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
120 Adds a handler to the end of the static list of format handlers.
122 \docparam{handler
}{A new image format handler object. There is usually only one instance
123 of a given handler class in an application session.
}
127 \helpref{wxImageHandler
}{wximagehandler
}
129 \pythonnote{In wxPython this static method is named
\tt{wxImage_AddHandler
}.
}
130 \membersection{wxImage::CleanUpHandlers
}
132 \func{static void
}{CleanUpHandlers
}{\void}
134 Deletes all image handlers.
136 This function is called by wxWindows on exit.
138 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
140 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
142 Converts the image to a platform-specific bitmap object. This has to be done
143 to actually display an image as you cannot draw an image directly on a window.
144 The resulting bitmap will use the colour depth of the current system which entails
145 that a (crude) colour reduction has to take place. When in
8-bit mode, this
146 routine will use a
color cube created on program start-up to look up colors.
147 Still, the image quality won't be perfect for photo images.
149 \membersection{wxImage::Create
}\label{wximagecreate
}
151 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
153 Creates a fresh image.
155 \wxheading{Parameters
}
157 \docparam{width
}{The width of the image in pixels.
}
159 \docparam{height
}{The height of the image in pixels.
}
161 \wxheading{Return value
}
163 TRUE if the call succeeded, FALSE otherwise.
165 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
167 \func{bool
}{Destroy
}{\void}
169 Destroys the image data.
171 \membersection{wxImage::FindHandler
}
173 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
175 Finds the handler with the given name.
177 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
179 Finds the handler associated with the given extension and type.
181 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
183 Finds the handler associated with the given image type.
185 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
187 Finds the handler associated with the given MIME type.
189 \docparam{name
}{The handler name.
}
191 \docparam{extension
}{The file extension, such as ``bmp".
}
193 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
195 \docparam{mimetype
}{MIME type.
}
197 \wxheading{Return value
}
199 A pointer to the handler if found, NULL otherwise.
203 \helpref{wxImageHandler
}{wximagehandler
}
205 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
207 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
209 Returns the blue intensity at the given coordinate.
211 \membersection{wxImage::GetData
}\label{wximagegetdata
}
213 \constfunc{unsigned char*
}{GetData
}{\void}
215 Returns the image data as an array. This is most often used when doing
216 direct image manipulation. The return value points to an array of
217 chararcters in RGBGBRGB... format.
219 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
221 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
223 Returns the green intensity at the given coordinate.
225 \membersection{wxImage::GetRed
}\label{wximagegetred
}
227 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
229 Returns the red intensity at the given coordinate.
231 \membersection{wxImage::GetHandlers
}
233 \func{static wxList\&
}{GetHandlers
}{\void}
235 Returns the static list of image format handlers.
239 \helpref{wxImageHandler
}{wximagehandler
}
241 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
243 \constfunc{int
}{GetHeight
}{\void}
245 Gets the height of the image in pixels.
247 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
249 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
251 Gets the blue value of the mask colour.
253 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
255 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
257 Gets the green value of the mask colour.
259 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
261 \constfunc{unsigned char
}{GetMaskRed
}{\void}
263 Gets the red value of the mask colour.
265 \membersection{wxImage::GetSubImage
}\label{wximagegetsubimage
}
267 \constfunc{wxImage
}{GetSubImage
}{\param{const wxRect&
}{rect
}}
269 Returns a sub image of the current one as long as the rect belongs entirely to
272 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
274 \constfunc{int
}{GetWidth
}{\void}
276 Gets the width of the image in pixels.
280 \helpref{wxImage::GetHeight
}{wximagegetheight
}
282 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
284 \constfunc{bool
}{HasMask
}{\void}
286 Returns TRUE if there is a mask active, FALSE otherwise.
288 \membersection{wxImage::InitStandardHandlers
}
290 \func{static void
}{InitStandardHandlers
}{\void}
292 Internal use only. Adds standard image format handlers. It only install BMP
293 for the time being, which is use by wxBitmap.
295 This function is called by wxWindows on startup, and shouldn't be called by
300 \helpref{wxImageHandler
}{wximagehandler
}
301 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
303 \membersection{wxImage::InsertHandler
}
305 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
307 Adds a handler at the start of the static list of format handlers.
309 \docparam{handler
}{A new image format handler object. There is usually only one instance
310 of a given handler class in an application session.
}
314 \helpref{wxImageHandler
}{wximagehandler
}
316 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
318 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
320 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
}}
322 Loads an image from a file. If no handler type is provided, the library will
323 try to use wxBITMAP
\_TYPE\_BMP.
325 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
327 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
}}
329 Loads an image from an input stream.
331 \wxheading{Parameters
}
333 \docparam{name
}{A filename.
334 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
336 \docparam{stream
}{An input stream.
337 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
339 \docparam{type
}{One of the following values:
343 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
344 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF image file.
}
345 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
346 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Load a PCX image file.
}
347 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
348 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Load a PNM image file.
}
351 The validity of these flags depends on the platform and wxWindows configuration.
}
353 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
355 \wxheading{Return value
}
357 TRUE if the operation succeeded, FALSE otherwise.
361 \helpref{wxImage::SaveFile
}{wximagesavefile
}
363 \pythonnote{In place of a single overloaded method name, wxPython
364 implements the following methods:
\par
365 \indented{2cm
}{\begin{twocollist
}
366 \twocolitem{\bf{LoadFile(filename, type)
}}{Loads an image of the given
368 \twocolitem{\bf{LoadMimeFile(filename, mimetype)
}}{Loads an image of the given
369 mimetype from a file
}
374 \membersection{wxImage::Ok
}\label{wximageok
}
376 \constfunc{bool
}{Ok
}{\void}
378 Returns TRUE if image data is present.
380 \membersection{wxImage::RemoveHandler
}
382 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
384 Finds the handler with the given name, and removes it. The handler
387 \docparam{name
}{The handler name.
}
389 \wxheading{Return value
}
391 TRUE if the handler was found and removed, FALSE otherwise.
395 \helpref{wxImageHandler
}{wximagehandler
}
397 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
399 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
401 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
403 Saves a image in the named file.
405 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
407 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
409 Saves a image in the given stream.
411 \wxheading{Parameters
}
413 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
415 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
417 \docparam{type
}{Currently two types can be used:
421 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
422 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
425 The validity of these flags depends on the platform and wxWindows configuration
426 as well as user-added handlers.
}
428 \docparam{mimetype
}{MIME type.
}
430 \wxheading{Return value
}
432 TRUE if the operation succeeded, FALSE otherwise.
436 Depending on how wxWindows has been configured, not all formats may be available.
440 \helpref{wxImage::LoadFile
}{wximageloadfile
}
442 \pythonnote{In place of a single overloaded method name, wxPython
443 implements the following methods:
\par
444 \indented{2cm
}{\begin{twocollist
}
445 \twocolitem{\bf{SaveFile(filename, type)
}}{Saves the image using the given
446 type to the named file
}
447 \twocolitem{\bf{SaveMimeFile(filename, mimetype)
}}{Saves the image using the given
448 mimetype to the named file
}
452 \membersection{wxImage::Rescale
}\label{wximagerescale
}
454 \func{wxImage
}{Rescale
}{\param{int
}{ width
},
\param{int
}{ height
}}
456 Changes the size of the image in-place: after a call to this function, the
457 image will have the given width and height.
461 \helpref{Scale
}{wximagescale
}
463 \membersection{wxImage::Scale
}\label{wximagescale
}
465 \constfunc{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
467 Returns a scaled version of the image. This is also useful for
468 scaling bitmaps in general as the only other way to scale bitmaps
469 is to blit a wxMemoryDC into another wxMemoryDC.
471 It may be mentioned that the GTK post uses this function internally
472 to scale bitmaps when using mapping mode in wxDC.
477 // get the bitmap from somewhere
480 // rescale it to have size of
32*
32
481 if ( bmp.GetWidth() !=
32 || bmp.GetHeight() !=
32 )
484 bmp = image.Scale(
32,
32).ConvertToBitmap();
486 // another possibility:
487 image.Rescale(
32,
32);
495 \helpref{Rescale
}{wximagerescale
}
497 \membersection{wxImage::SetData
}\label{wximagesetdata
}
499 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
501 Sets the image data without performing checks. The data given must have
502 the size (width*height*
3) or results will be unexpected. Don't use this
503 method if you aren't sure you know what you are doing.
505 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
507 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
509 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
511 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
513 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
515 Sets the mask colour for this image (and tells the image to use the mask).
517 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
519 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
521 Sets the pixel at the given coordinate. This routine performs bounds-checks
522 for the coordinate so it can be considered a safe way to manipulate the
523 data, but in some cases this might be too slow so that the data will have to
524 be set directly. In that case you have to get that data by calling GetData().
526 \membersection{wxImage::operator $=$
}
528 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
530 Assignment operator. This operator does not copy any data, but instead
531 passes a pointer to the data in
{\it image
} and increments a reference
532 counter. It is a fast operation.
534 \wxheading{Parameters
}
536 \docparam{image
}{Image to assign.
}
538 \wxheading{Return value
}
540 Returns 'this' object.
542 \membersection{wxImage::operator $==$
}
544 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
546 Equality operator. This operator tests whether the internal data pointers are
549 \wxheading{Parameters
}
551 \docparam{image
}{Image to compare with 'this'
}
553 \wxheading{Return value
}
555 Returns TRUE if the images were effectively equal, FALSE otherwise.
557 \membersection{wxImage::operator $!=$
}
559 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
561 Inequality operator. This operator tests whether the internal data pointers are
562 unequal (a fast test).
564 \wxheading{Parameters
}
566 \docparam{image
}{Image to compare with 'this'
}
568 \wxheading{Return value
}
570 Returns TRUE if the images were unequal, FALSE otherwise.
572 \section{\class{wxImageHandler
}}\label{wximagehandler
}
574 This is the base class for implementing image file loading/saving, and image creation from data.
575 It is used within wxImage and is not normally seen by the application.
577 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
578 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
579 application initialisation.
581 \wxheading{Note (Legal Issue)
}
583 This software is based in part on the work of the Independent JPEG Group.
585 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
588 \wxheading{Derived from
}
590 \helpref{wxObject
}{wxobject
}
592 \wxheading{Include files
}
598 \helpref{wxImage
}{wximage
}
599 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
601 \latexignore{\rtfignore{\wxheading{Members
}}}
603 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
605 \func{}{wxImageHandler
}{\void}
607 Default constructor. In your own default constructor, initialise the members
608 m
\_name, m
\_extension and m
\_type.
610 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
612 \func{}{\destruct{wxImageHandler
}}{\void}
614 Destroys the wxImageHandler object.
616 \membersection{wxImageHandler::GetName
}
618 \constfunc{wxString
}{GetName
}{\void}
620 Gets the name of this handler.
622 \membersection{wxImageHandler::GetExtension
}
624 \constfunc{wxString
}{GetExtension
}{\void}
626 Gets the file extension associated with this handler.
628 \membersection{wxImageHandler::GetType
}
630 \constfunc{long
}{GetType
}{\void}
632 Gets the image type associated with this handler.
634 \membersection{wxImageHandler::GetMimeType
}
636 \constfunc{wxString
}{GetMimeType
}{\void}
638 Gets the MIME type associated with this handler.
640 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
642 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
644 Loads a image from a stream, putting the resulting data into
{\it image
}.
646 \wxheading{Parameters
}
648 \docparam{image
}{The image object which is to be affected by this operation.
}
650 \docparam{stream
}{Opened input stream.
651 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
653 \wxheading{Return value
}
655 TRUE if the operation succeeded, FALSE otherwise.
659 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
660 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
661 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
663 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
665 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
667 Saves a image in the output stream.
669 \wxheading{Parameters
}
671 \docparam{image
}{The image object which is to be affected by this operation.
}
673 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
675 \wxheading{Return value
}
677 TRUE if the operation succeeded, FALSE otherwise.
681 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
682 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
683 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
685 \membersection{wxImageHandler::SetName
}
687 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
689 Sets the handler name.
691 \wxheading{Parameters
}
693 \docparam{name
}{Handler name.
}
695 \membersection{wxImageHandler::SetExtension
}
697 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
699 Sets the handler extension.
701 \wxheading{Parameters
}
703 \docparam{extension
}{Handler extension.
}
705 \membersection{wxImageHandler::SetType
}
707 \func{void
}{SetType
}{\param{long
}{type
}}
709 Sets the handler type.
711 \wxheading{Parameters
}
713 \docparam{name
}{Handler type.
}
716 \membersection{wxImageHandler::SetMimeType
}
718 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
720 Sets the handler MIME type.
722 \wxheading{Parameters
}
724 \docparam{mimename
}{Handler MIME type.
}