1 \section{\class{wxImage
}}\label{wximage
}
3 This class encapsulates a platform-independent image. An image can be created
4 from data, or using
\helpref{wxBitmap::ConvertToImage
}{wxbitmapconverttoimage
}. 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
\helpref{wxDC
}{wxdc
}. Instead,
10 a platform-specific
\helpref{wxBitmap
}{wxbitmap
} object must be created from it using
11 the
\helpref{wxBitmap::wxBitmap(wxImage,int depth)
}{wxbitmapconstr
} constructor.
13 be drawn in a device context, using
\helpref{wxDC::DrawBitmap
}{wxdcdrawbitmap
}.
15 One colour value of the image may be used as a mask colour which will lead to the automatic
16 creation of a
\helpref{wxMask
}{wxmask
} object associated to the bitmap object.
18 \wxheading{Available image handlers
}
20 The following image handlers are available.
{\bf wxBMPHandler
} is always
21 installed by default. To use other image formats, install the appropriate
22 handler with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
23 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
27 \twocolitem{\indexit{wxBMPHandler
}}{For loading and saving, always installed.
}
28 \twocolitem{\indexit{wxPNGHandler
}}{For loading and saving.
}
29 \twocolitem{\indexit{wxJPEGHandler
}}{For loading and saving.
}
30 \twocolitem{\indexit{wxGIFHandler
}}{Only for loading, due to legal issues.
}
31 \twocolitem{\indexit{wxPCXHandler
}}{For loading and saving (see below).
}
32 \twocolitem{\indexit{wxPNMHandler
}}{For loading and saving (see below).
}
33 \twocolitem{\indexit{wxTIFFHandler
}}{For loading and saving.
}
34 \twocolitem{\indexit{wxIFFHandler
}}{For loading only.
}
35 \twocolitem{\indexit{wxXPMHandler
}}{For loading and saving.
}
36 \twocolitem{\indexit{wxICOHandler
}}{For loading and saving.
}
37 \twocolitem{\indexit{wxCURHandler
}}{For loading and saving.
}
38 \twocolitem{\indexit{wxANIHandler
}}{For loading only.
}
41 When saving in PCX format,
{\bf wxPCXHandler
} will count the number of
42 different colours in the image; if there are
256 or less colours, it will
43 save as
8 bit, else it will save as
24 bit.
45 Loading PNMs only works for ASCII or raw RGB images. When saving in
46 PNM format,
{\bf wxPNMHandler
} will always save as raw RGB.
48 \wxheading{Derived from
}
50 \helpref{wxObject
}{wxobject
}
52 \wxheading{Include files
}
58 \helpref{wxBitmap
}{wxbitmap
},
59 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
61 \latexignore{\rtfignore{\wxheading{Members
}}}
63 \membersection{wxImage::wxImage
}\label{wximageconstr
}
65 \func{}{wxImage
}{\void}
69 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
73 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
75 (Deprecated form, use
\helpref{wxBitmap::ConvertToImage
}{wxbitmapconverttoimage
}
76 instead.) Constructs an image from a platform-dependent bitmap. This preserves
77 mask information so that bitmaps and images can be converted back
78 and forth without loss in that respect.
80 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
82 Creates an image with the given width and height.
84 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{unsigned char*
}{ data
},
\param{bool
}{ static
\_data=false
}}
86 Creates an image from given data with the given width and height. If
87 {\it static
\_data} is true, then wxImage will not delete the actual
88 image data in its destructor, otherwise it will free it by calling
91 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
93 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
95 Loads an image from a file.
97 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
99 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
101 Loads an image from an input stream.
103 \wxheading{Parameters
}
105 \docparam{width
}{Specifies the width of the image.
}
107 \docparam{height
}{Specifies the height of the image.
}
109 \docparam{name
}{Name of the file from which to load the image.
}
111 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
113 \docparam{type
}{May be one of the following:
117 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
118 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
119 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
120 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
121 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
122 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
123 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
124 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
125 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
126 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
127 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
128 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
131 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
133 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
134 This is only used by GIF, ICO and TIFF handlers. The default value (-
1) means
135 "choose the default image" and is interpreted as the first image (index=
0) by
136 the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.
}
140 Depending on how wxWindows has been configured, not all formats may be available.
142 Note: any handler other than BMP must be previously
143 initialized with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
144 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
146 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
147 hotspot for loaded cursor file:
149 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
150 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
156 \helpref{wxImage::LoadFile
}{wximageloadfile
}
158 \pythonnote{Constructors supported by wxPython are:
\par
159 \indented{2cm
}{\begin{twocollist
}
160 \twocolitem{{\bf wxImage(name, flag)
}}{Loads an image from a file
}
161 \twocolitem{{\bf wxNullImage()
}}{Create a null image (has no size or
163 \twocolitem{{\bf wxEmptyImage(width, height)
}}{Creates an empty image
165 \twocolitem{{\bf wxImageFromMime(name, mimetype
}}{Creates an image from
166 the given file of the given mimetype
}
167 \twocolitem{{\bf wxImageFromBitmap(bitmap)
}}{Creates an image from a
168 platform-dependent bitmap
}
172 \perlnote{Constructors supported by wxPerl are:
\par
174 \item{Wx::Image->new( bitmap )
}
175 \item{Wx::Image->new( width, height )
}
176 \item{Wx::Image->new( name, type )
}
177 \item{Wx::Image->new( name, mimetype )
}
181 \membersection{wxImage::
\destruct{wxImage
}}
183 \func{}{\destruct{wxImage
}}{\void}
187 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
189 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
191 Adds a handler to the end of the static list of format handlers.
193 \docparam{handler
}{A new image format handler object. There is usually only one instance
194 of a given handler class in an application session.
}
198 \helpref{wxImageHandler
}{wximagehandler
}
200 \func{bool
}{CanRead
}{\param{const wxString\&
}{ filename
}}
202 returns true if the current image handlers can read this file
204 \pythonnote{In wxPython this static method is named
{\tt wxImage
\_AddHandler}.
}
205 \membersection{wxImage::CleanUpHandlers
}
207 \func{static void
}{CleanUpHandlers
}{\void}
209 Deletes all image handlers.
211 This function is called by wxWindows on exit.
213 \membersection{wxImage::ComputeHistogram
}\label{wximagecomputehistogram
}
215 \constfunc{unsigned long
}{ComputeHistogram
}{\param{wxImageHistogram\&
}{histogram
}}
217 Computes the histogram of the image.
{\it histogram
} is a reference to
218 wxImageHistogram object. wxImageHistogram is a specialization of
219 \helpref{wxHashMap
}{wxhashmap
} "template" and is defined as follows:
222 class WXDLLEXPORT wxImageHistogramEntry
225 wxImageHistogramEntry() : index(
0), value(
0)
{}
230 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
231 wxIntegerHash, wxIntegerEqual,
235 \wxheading{Return value
}
237 Returns number of colours in the histogram.
239 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
241 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
243 Deprecated, use equivalent
\helpref{wxBitmap constructor
}{wxbitmapconstr
}
244 (which takes wxImage and depth as its arguments) instead.
246 \membersection{wxImage::ConvertToMono
}\label{wxbitmapconverttomono
}
248 \constfunc{wxImage
}{ConvertToMono
}{\param{unsigned char
}{ r
},
\param{unsigned char
}{ g
},
\param{unsigned char
}{ b
}}
250 Returns monochromatic version of the image. The returned image has white
251 colour where the original has
{\it (r,g,b)
} colour and black colour
254 \membersection{wxImage::Copy
}\label{wximagecopy
}
256 \constfunc{wxImage
}{Copy
}{\void}
258 Returns an identical copy of the image.
260 \membersection{wxImage::Create
}\label{wximagecreate
}
262 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
264 Creates a fresh image.
266 \wxheading{Parameters
}
268 \docparam{width
}{The width of the image in pixels.
}
270 \docparam{height
}{The height of the image in pixels.
}
272 \wxheading{Return value
}
274 true if the call succeeded, false otherwise.
276 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
278 \func{bool
}{Destroy
}{\void}
280 Destroys the image data.
282 \membersection{wxImage::FindFirstUnusedColour
}\label{wximagefindfirstunusedcolour
}
284 \func{bool
}{FindFirstUnusedColour
}{\param{unsigned char *
}{ r
},
\param{unsigned char *
}{ g
},
\param{unsigned char *
}{ b
},
\param{unsigned char
}{ startR =
1},
\param{unsigned char
}{ startG =
0},
\param{unsigned char
}{ startB =
0}}
286 \wxheading{Parameters
}
288 \docparam{r,g,b
}{Pointers to variables to save the colour.
}
290 \docparam{startR,startG,startB
}{Initial values of the colour. Returned colour
291 will have RGB values equal to or greater than these.
}
293 Finds the first colour that is never used in the image. The search begins at
294 given initial colour and continues by increasing R, G and B components (in this
295 order) by
1 until an unused colour is found or the colour space exhausted.
297 \wxheading{Return value
}
299 Returns false if there is no unused colour left, true on success.
303 Note that this method involves computing the histogram, which is
304 computationally intensive operation.
306 \membersection{wxImage::FindHandler
}
308 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
310 Finds the handler with the given name.
312 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
314 Finds the handler associated with the given extension and type.
316 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
318 Finds the handler associated with the given image type.
320 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
322 Finds the handler associated with the given MIME type.
324 \docparam{name
}{The handler name.
}
326 \docparam{extension
}{The file extension, such as ``bmp".
}
328 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
330 \docparam{mimetype
}{MIME type.
}
332 \wxheading{Return value
}
334 A pointer to the handler if found, NULL otherwise.
338 \helpref{wxImageHandler
}{wximagehandler
}
340 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
342 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
344 Returns the blue intensity at the given coordinate.
346 \membersection{wxImage::GetData
}\label{wximagegetdata
}
348 \constfunc{unsigned char*
}{GetData
}{\void}
350 Returns the image data as an array. This is most often used when doing
351 direct image manipulation. The return value points to an array of
352 characters in RGBRGBRGB$
\ldots$ format.
354 You should not delete the returned pointer nor pass it to
355 \helpref{wxImage::SetData
}{wximagesetdata
}.
357 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
359 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
361 Returns the green intensity at the given coordinate.
363 \membersection{wxImage::GetImageCount
}\label{wximagegetimagecount
}
365 \func{static int
}{GetImageCount
}{\param{const wxString\&
}{ filename
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
367 \func{static int
}{GetImageCount
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
369 If the image file contains more than one image and the image handler is capable
370 of retrieving these individually, this function will return the number of
373 \docparam{name
}{Name of the file to query.
}
375 \docparam{stream
}{Opened input stream with image data. Currently, the stream must support seeking.
}
377 \docparam{type
}{May be one of the following:
381 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
382 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
383 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
384 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
385 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
386 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
387 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
388 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
389 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
390 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
391 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
392 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
395 \wxheading{Return value
}
397 Number of available images. For most image handlers, this is
1 (exceptions
398 are TIFF and ICO formats).
400 \membersection{wxImage::GetHandlers
}
402 \func{static wxList\&
}{GetHandlers
}{\void}
404 Returns the static list of image format handlers.
408 \helpref{wxImageHandler
}{wximagehandler
}
410 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
412 \constfunc{int
}{GetHeight
}{\void}
414 Gets the height of the image in pixels.
416 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
418 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
420 Gets the blue value of the mask colour.
422 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
424 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
426 Gets the green value of the mask colour.
428 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
430 \constfunc{unsigned char
}{GetMaskRed
}{\void}
432 Gets the red value of the mask colour.
434 \membersection{wxImage::GetPalette
}\label{wximagegetpalette
}
436 \constfunc{const wxPalette\&
}{GetPalette
}{\void}
438 Returns the palette associated with the image. Currently the palette is only
439 used when converting to wxBitmap under Windows.
441 Eventually wxImage handlers will set the palette if one exists in the image file.
443 \membersection{wxImage::GetRed
}\label{wximagegetred
}
445 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
447 Returns the red intensity at the given coordinate.
449 \membersection{wxImage::GetSubImage
}\label{wximagegetsubimage
}
451 \constfunc{wxImage
}{GetSubImage
}{\param{const wxRect\&
}{ rect
}}
453 Returns a sub image of the current one as long as the rect belongs entirely to
456 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
458 \constfunc{int
}{GetWidth
}{\void}
460 Gets the width of the image in pixels.
464 \helpref{wxImage::GetHeight
}{wximagegetheight
}
466 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
468 \constfunc{bool
}{HasMask
}{\void}
470 Returns true if there is a mask active, false otherwise.
472 \membersection{wxImage::GetOption
}\label{wximagegetoption
}
474 \constfunc{wxString
}{GetOption
}{\param{const wxString\&
}{ name
}}
476 Gets a user-defined option. The function is case-insensitive to
{\it name
}.
478 For example, when saving as a JPEG file, the option
{\bf quality
} is
479 used, which is a number between
0 and
100 (
0 is terrible,
100 is very good).
483 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
484 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
},
\rtfsp
485 \helpref{wxImage::HasOption
}{wximagehasoption
}
487 \membersection{wxImage::GetOptionInt
}\label{wximagegetoptionint
}
489 \constfunc{int
}{GetOptionInt
}{\param{const wxString\&
}{ name
}}
491 Gets a user-defined option as an integer. The function is case-insensitive to
{\it name
}.
495 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
496 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
497 \helpref{wxImage::HasOption
}{wximagehasoption
}
499 \membersection{wxImage::HasOption
}\label{wximagehasoption
}
501 \constfunc{bool
}{HasOption
}{\param{const wxString\&
}{ name
}}
503 Returns true if the given option is present. The function is case-insensitive to
{\it name
}.
507 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
508 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
509 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
}
511 \membersection{wxImage::InitStandardHandlers
}
513 \func{static void
}{InitStandardHandlers
}{\void}
515 Internal use only. Adds standard image format handlers. It only install BMP
516 for the time being, which is used by wxBitmap.
518 This function is called by wxWindows on startup, and shouldn't be called by
523 \helpref{wxImageHandler
}{wximagehandler
},
524 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
526 \membersection{wxImage::InsertHandler
}
528 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
530 Adds a handler at the start of the static list of format handlers.
532 \docparam{handler
}{A new image format handler object. There is usually only one instance
533 of a given handler class in an application session.
}
537 \helpref{wxImageHandler
}{wximagehandler
}
539 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
541 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
543 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
545 Loads an image from a file. If no handler type is provided, the library will
546 try to autodetect the format.
548 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
},
\param{int
}{ index = -
1}}
550 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
552 Loads an image from an input stream.
554 \wxheading{Parameters
}
556 \docparam{name
}{Name of the file from which to load the image.
}
558 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
560 \docparam{type
}{One of the following values:
564 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
565 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF image file.
}
566 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
567 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Load a PCX image file.
}
568 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
569 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Load a PNM image file.
}
570 \twocolitem{{\bf wxBITMAP
\_TYPE\_TIF}}{Load a TIFF image file.
}
571 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Load a XPM image file.
}
572 \twocolitem{{\bf wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
573 \twocolitem{{\bf wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
574 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
575 \twocolitem{{\bf wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
578 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
580 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
581 This is only used by GIF, ICO and TIFF handlers. The default value (-
1) means
582 "choose the default image" and is interpreted as the first image (index=
0) by
583 the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.
}
587 Depending on how wxWindows has been configured, not all formats may be available.
589 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
590 hotspot for loaded cursor file:
592 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
593 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
597 \wxheading{Return value
}
599 true if the operation succeeded, false otherwise. If the optional index parameter is out of range,
600 false is returned and a call to wxLogError() takes place.
604 \helpref{wxImage::SaveFile
}{wximagesavefile
}
606 \pythonnote{In place of a single overloaded method name, wxPython
607 implements the following methods:
\par
608 \indented{2cm
}{\begin{twocollist
}
609 \twocolitem{{\bf LoadFile(filename, type)
}}{Loads an image of the given
611 \twocolitem{{\bf LoadMimeFile(filename, mimetype)
}}{Loads an image of the given
612 mimetype from a file
}
616 \perlnote{Methods supported by wxPerl are:
\par
618 \item{bitmap->LoadFile( name, type )
}
619 \item{bitmap->LoadFile( name, mimetype )
}
624 \membersection{wxImage::Ok
}\label{wximageok
}
626 \constfunc{bool
}{Ok
}{\void}
628 Returns true if image data is present.
630 \membersection{wxImage::RemoveHandler
}
632 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
634 Finds the handler with the given name, and removes it. The handler
637 \docparam{name
}{The handler name.
}
639 \wxheading{Return value
}
641 true if the handler was found and removed, false otherwise.
645 \helpref{wxImageHandler
}{wximagehandler
}
647 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
649 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
651 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
653 Saves an image in the named file.
655 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
}}
657 Saves an image in the named file. File type is determined from the extension of the
658 file name. Note that this function may fail if the extension is not recognized! You
659 can use one of the forms above to save images to files with non-standard extensions.
661 \constfunc{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
663 \constfunc{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
665 Saves an image in the given stream.
667 \wxheading{Parameters
}
669 \docparam{name
}{Name of the file to save the image to.
}
671 \docparam{stream
}{Opened output stream to save the image to.
}
673 \docparam{type
}{Currently these types can be used:
677 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Save a BMP image file.
}
678 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
679 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
680 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Save a PCX image file (tries to save as
8-bit if possible, falls back to
24-bit otherwise).
}
681 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Save a PNM image file (as raw RGB always).
}
682 \twocolitem{{\bf wxBITMAP
\_TYPE\_TIFF}}{Save a TIFF image file.
}
683 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Save a XPM image file.
}
684 \twocolitem{{\bf wxBITMAP
\_TYPE\_ICO}}{Save a Windows icon file (ICO) (the size may be up to
255 wide by
127 high. A single image is saved in
8 colors at the size supplied).
}
685 \twocolitem{{\bf wxBITMAP
\_TYPE\_CUR}}{Save a Windows cursor file (CUR).
}
688 \docparam{mimetype
}{MIME type.
}
690 \wxheading{Return value
}
692 true if the operation succeeded, false otherwise.
696 Depending on how wxWindows has been configured, not all formats may be available.
698 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to set the
699 hotspot before saving an image into a cursor file (default hotspot is in
700 the centre of the image):
702 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
703 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
709 \helpref{wxImage::LoadFile
}{wximageloadfile
}
711 \pythonnote{In place of a single overloaded method name, wxPython
712 implements the following methods:
\par
713 \indented{2cm
}{\begin{twocollist
}
714 \twocolitem{{\bf SaveFile(filename, type)
}}{Saves the image using the given
715 type to the named file
}
716 \twocolitem{{\bf SaveMimeFile(filename, mimetype)
}}{Saves the image using the given
717 mimetype to the named file
}
721 \perlnote{Methods supported by wxPerl are:
\par
723 \item{bitmap->SaveFile( name, type )
}
724 \item{bitmap->SaveFile( name, mimetype )
}
728 \membersection{wxImage::Mirror
}\label{wximagemirror
}
730 \constfunc{wxImage
}{Mirror
}{\param{bool
}{ horizontally = true
}}
732 Returns a mirrored copy of the image. The parameter
{\it horizontally
}
733 indicates the orientation.
735 \membersection{wxImage::Replace
}\label{wximagereplace
}
737 \func{void
}{Replace
}{\param{unsigned char
}{ r1
},
\param{unsigned char
}{ g1
},
\param{unsigned char
}{ b1
},
738 \param{unsigned char
}{ r2
},
\param{unsigned char
}{ g2
},
\param{unsigned char
}{ b2
}}
740 Replaces the colour specified by
{\it r1,g1,b1
} by the colour
{\it r2,g2,b2
}.
742 \membersection{wxImage::Rescale
}\label{wximagerescale
}
744 \func{wxImage \&
}{Rescale
}{\param{int
}{ width
},
\param{int
}{ height
}}
746 Changes the size of the image in-place: after a call to this function, the
747 image will have the given width and height.
749 Returns the (modified) image itself.
753 \helpref{Scale
}{wximagescale
}
755 \membersection{wxImage::Rotate
}\label{wximagerotate
}
757 \func{wxImage
}{Rotate
}{\param{double
}{ angle
},
\param{const wxPoint\&
}{rotationCentre
},
758 \param{bool
}{ interpolating = true
},
\param{wxPoint*
}{ offsetAfterRotation = NULL
}}
760 Rotates the image about the given point, by
{\it angle
} radians. Passing true
761 to
{\it interpolating
} results in better image quality, but is slower. If the
762 image has a mask, then the mask colour is used for the uncovered pixels in the
763 rotated image background. Else, black (rgb
0,
0,
0) will be used.
765 Returns the rotated image, leaving this image intact.
767 \membersection{wxImage::Rotate90
}\label{wximagerotate90
}
769 \constfunc{wxImage
}{Rotate90
}{\param{bool
}{ clockwise = true
}}
771 Returns a copy of the image rotated
90 degrees in the direction
772 indicated by
{\it clockwise
}.
774 \membersection{wxImage::Scale
}\label{wximagescale
}
776 \constfunc{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
778 Returns a scaled version of the image. This is also useful for
779 scaling bitmaps in general as the only other way to scale bitmaps
780 is to blit a wxMemoryDC into another wxMemoryDC.
782 It may be mentioned that the GTK port uses this function internally
783 to scale bitmaps when using mapping modes in wxDC.
788 // get the bitmap from somewhere
791 // rescale it to have size of
32*
32
792 if ( bmp.GetWidth() !=
32 || bmp.GetHeight() !=
32 )
795 bmp = wxBitmap(image.Scale(
32,
32));
797 // another possibility:
798 image.Rescale(
32,
32);
806 \helpref{Rescale
}{wximagerescale
}
808 \membersection{wxImage::SetData
}\label{wximagesetdata
}
810 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
812 Sets the image data without performing checks. The data given must have
813 the size (width*height*
3) or results will be unexpected. Don't use this
814 method if you aren't sure you know what you are doing.
816 The data must have been allocated with malloc(), NOT with operator new.
818 After this call the pointer to the data is owned by the wxImage object,
819 that will be responsible for deleting it.
820 Do not pass to this function a pointer obtained through
821 \helpref{wxImage::GetData
}{wximagegetdata
}.
823 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
825 \func{void
}{SetMask
}{\param{bool
}{ hasMask = true
}}
827 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
829 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
831 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
833 Sets the mask colour for this image (and tells the image to use the mask).
835 \membersection{wxImage::SetMaskFromImage
}\label{wximagesetmaskfromimage
}
837 \func{bool
}{SetMaskFromImage
}{\param{const wxImage\&
}{ mask
},
\param{unsigned char
}{ mr
},
\param{unsigned char
}{ mg
},
\param{unsigned char
}{ mb
}}
839 \wxheading{Parameters
}
841 \docparam{mask
}{The mask image to extract mask shape from. Must have same dimensions as the image.
}
843 \docparam{mr,mg,mb
}{RGB value of pixels in
{\it mask
} that will be used to create the mask.
}
845 Sets image's mask so that the pixels that have RGB value of
{\it mr,mg,mb
}
846 in
{\it mask
} will be masked in the image. This is done by first finding an
847 unused colour in the image, setting this colour as the mask colour and then
848 using this colour to draw all pixels in the image who corresponding pixel
849 in
{\it mask
} has given RGB value.
851 \wxheading{Return value
}
853 Returns false if
{\it mask
} does not have same dimensions as the image or if
854 there is no unused colour left. Returns true if the mask was successfully
859 Note that this method involves computing the histogram, which is
860 computationally intensive operation.
862 \membersection{wxImage::SetOption
}\label{wximagesetoption
}
864 \func{void
}{SetOption
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ value
}}
866 \func{void
}{SetOption
}{\param{const wxString\&
}{ name
},
\param{int
}{ value
}}
868 Sets a user-defined option. The function is case-insensitive to
{\it name
}.
870 For example, when saving as a JPEG file, the option
{\bf quality
} is
871 used, which is a number between
0 and
100 (
0 is terrible,
100 is very good).
875 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
876 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
},
\rtfsp
877 \helpref{wxImage::HasOption
}{wximagehasoption
}
879 \membersection{wxImage::SetPalette
}\label{wximagesetpalette
}
881 \func{void
}{SetPalette
}{\param{const wxPalette\&
}{ palette
}}
883 Associates a palette with the image. The palette may be used when converting
884 wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).
886 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
888 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{green
},
\param{unsigned char
}{blue
}}
890 Sets the pixel at the given coordinate. This routine performs bounds-checks
891 for the coordinate so it can be considered a safe way to manipulate the
892 data, but in some cases this might be too slow so that the data will have to
893 be set directly. In that case you will have to get access to the image data
894 using the
\helpref{GetData
}{wximagegetdata
} method.
896 \membersection{wxImage::operator $=$
}
898 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
900 Assignment operator. This operator does not copy any data, but instead
901 passes a pointer to the data in
{\it image
} and increments a reference
902 counter. It is a fast operation.
904 \wxheading{Parameters
}
906 \docparam{image
}{Image to assign.
}
908 \wxheading{Return value
}
910 Returns 'this' object.
912 \membersection{wxImage::operator $==$
}
914 \constfunc{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
916 Equality operator. This operator tests whether the internal data pointers are
919 \wxheading{Parameters
}
921 \docparam{image
}{Image to compare with 'this'
}
923 \wxheading{Return value
}
925 Returns true if the images were effectively equal, false otherwise.
927 \membersection{wxImage::operator $!=$
}
929 \constfunc{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
931 Inequality operator. This operator tests whether the internal data pointers are
932 unequal (a fast test).
934 \wxheading{Parameters
}
936 \docparam{image
}{Image to compare with 'this'
}
938 \wxheading{Return value
}
940 Returns true if the images were unequal, false otherwise.
942 \section{\class{wxImageHandler
}}\label{wximagehandler
}
944 This is the base class for implementing image file loading/saving, and image creation from data.
945 It is used within wxImage and is not normally seen by the application.
947 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
948 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
949 application initialisation.
951 \wxheading{Note (Legal Issue)
}
953 This software is based in part on the work of the Independent JPEG Group.
955 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
958 \wxheading{Derived from
}
960 \helpref{wxObject
}{wxobject
}
962 \wxheading{Include files
}
968 \helpref{wxImage
}{wximage
},
969 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
971 \latexignore{\rtfignore{\wxheading{Members
}}}
973 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
975 \func{}{wxImageHandler
}{\void}
977 Default constructor. In your own default constructor, initialise the members
978 m
\_name, m
\_extension and m
\_type.
980 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
982 \func{}{\destruct{wxImageHandler
}}{\void}
984 Destroys the wxImageHandler object.
986 \membersection{wxImageHandler::GetName
}
988 \constfunc{wxString
}{GetName
}{\void}
990 Gets the name of this handler.
992 \membersection{wxImageHandler::GetExtension
}
994 \constfunc{wxString
}{GetExtension
}{\void}
996 Gets the file extension associated with this handler.
998 \membersection{wxImageHandler::GetImageCount
}\label{wximagehandlergetimagecount
}
1000 \func{int
}{GetImageCount
}{\param{wxInputStream\&
}{ stream
}}
1002 If the image file contains more than one image and the image handler is capable
1003 of retrieving these individually, this function will return the number of
1006 \docparam{stream
}{Opened input stream for reading image data. Currently, the stream must support seeking.
}
1008 \wxheading{Return value
}
1010 Number of available images. For most image handlers, this is
1 (exceptions
1011 are TIFF and ICO formats).
1013 \membersection{wxImageHandler::GetType
}
1015 \constfunc{long
}{GetType
}{\void}
1017 Gets the image type associated with this handler.
1019 \membersection{wxImageHandler::GetMimeType
}
1021 \constfunc{wxString
}{GetMimeType
}{\void}
1023 Gets the MIME type associated with this handler.
1025 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
1027 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
},
\param{bool
}{ verbose=true
},
\param{int
}{ index=
0}}
1029 Loads a image from a stream, putting the resulting data into
{\it image
}. If the image file contains
1030 more than one image and the image handler is capable of retrieving these individually,
{\it index
}
1031 indicates which image to read from the stream.
1033 \wxheading{Parameters
}
1035 \docparam{image
}{The image object which is to be affected by this operation.
}
1037 \docparam{stream
}{Opened input stream for reading image data.
}
1039 \docparam{verbose
}{If set to true, errors reported by the image handler will produce wxLogMessages.
}
1041 \docparam{index
}{The index of the image in the file (starting from zero).
}
1043 \wxheading{Return value
}
1045 true if the operation succeeded, false otherwise.
1047 \wxheading{See also
}
1049 \helpref{wxImage::LoadFile
}{wximageloadfile
},
1050 \helpref{wxImage::SaveFile
}{wximagesavefile
},
1051 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
1053 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
1055 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
1057 Saves a image in the output stream.
1059 \wxheading{Parameters
}
1061 \docparam{image
}{The image object which is to be affected by this operation.
}
1063 \docparam{stream
}{Opened output stream for writing the data.
}
1065 \wxheading{Return value
}
1067 true if the operation succeeded, false otherwise.
1069 \wxheading{See also
}
1071 \helpref{wxImage::LoadFile
}{wximageloadfile
},
1072 \helpref{wxImage::SaveFile
}{wximagesavefile
},
1073 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
1075 \membersection{wxImageHandler::SetName
}
1077 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
1079 Sets the handler name.
1081 \wxheading{Parameters
}
1083 \docparam{name
}{Handler name.
}
1085 \membersection{wxImageHandler::SetExtension
}
1087 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
1089 Sets the handler extension.
1091 \wxheading{Parameters
}
1093 \docparam{extension
}{Handler extension.
}
1095 \membersection{wxImageHandler::SetMimeType
}\label{wximagehandlersetmimetype
}
1097 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
1099 Sets the handler MIME type.
1101 \wxheading{Parameters
}
1103 \docparam{mimename
}{Handler MIME type.
}
1105 \membersection{wxImageHandler::SetType
}
1107 \func{void
}{SetType
}{\param{long
}{type
}}
1109 Sets the handler type.
1111 \wxheading{Parameters
}
1113 \docparam{name
}{Handler type.
}