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{Alpha channel support
}
20 Starting from wxWindows
2.5.0 wxImage supports alpha channel data, that is in
21 addition to a byte for the red, green and blue colour components for each pixel
22 it also stores a byte representing the pixel opacity. The alpha value of $
0$
23 corresponds to a transparent pixel (null opacity) while the value of $
255$
24 means that the pixel is
100\% opaque.
26 Unlike the RGB data, not all images have the alpha channel and before using
27 \helpref{GetAlpha
}{wximagegetalpha
} you should check if this image contains
28 alpha value with
\helpref{HasAlpha
}{wximagehasalpha
}. In fact, currently only
29 images loaded from PNG files with transparency information will have alpha
30 channel but support for it will be added to the other formats as well (as well
31 as support for saving images with alpha channel which is not still implemented
34 \wxheading{Available image handlers
}
36 The following image handlers are available.
{\bf wxBMPHandler
} is always
37 installed by default. To use other image formats, install the appropriate
38 handler with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
39 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
43 \twocolitem{\indexit{wxBMPHandler
}}{For loading and saving, always installed.
}
44 \twocolitem{\indexit{wxPNGHandler
}}{For loading (including alpha support) and saving.
}
45 \twocolitem{\indexit{wxJPEGHandler
}}{For loading and saving.
}
46 \twocolitem{\indexit{wxGIFHandler
}}{Only for loading, due to legal issues.
}
47 \twocolitem{\indexit{wxPCXHandler
}}{For loading and saving (see below).
}
48 \twocolitem{\indexit{wxPNMHandler
}}{For loading and saving (see below).
}
49 \twocolitem{\indexit{wxTIFFHandler
}}{For loading and saving.
}
50 \twocolitem{\indexit{wxIFFHandler
}}{For loading only.
}
51 \twocolitem{\indexit{wxXPMHandler
}}{For loading and saving.
}
52 \twocolitem{\indexit{wxICOHandler
}}{For loading and saving.
}
53 \twocolitem{\indexit{wxCURHandler
}}{For loading and saving.
}
54 \twocolitem{\indexit{wxANIHandler
}}{For loading only.
}
57 When saving in PCX format,
{\bf wxPCXHandler
} will count the number of
58 different colours in the image; if there are
256 or less colours, it will
59 save as
8 bit, else it will save as
24 bit.
61 Loading PNMs only works for ASCII or raw RGB images. When saving in
62 PNM format,
{\bf wxPNMHandler
} will always save as raw RGB.
64 \wxheading{Derived from
}
66 \helpref{wxObject
}{wxobject
}
68 \wxheading{Include files
}
74 \helpref{wxBitmap
}{wxbitmap
},
75 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
77 \latexignore{\rtfignore{\wxheading{Members
}}}
79 \membersection{wxImage::wxImage
}\label{wximageconstr
}
81 \func{}{wxImage
}{\void}
85 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
89 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
91 (Deprecated form, use
\helpref{wxBitmap::ConvertToImage
}{wxbitmapconverttoimage
}
92 instead.) Constructs an image from a platform-dependent bitmap. This preserves
93 mask information so that bitmaps and images can be converted back
94 and forth without loss in that respect.
96 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{bool
}{ clear=true
}}
98 Creates an image with the given width and height. If
{\it clear
} is true, the new image will be initialized to black.
99 Otherwise, the image data will be uninitialized.
101 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{unsigned char*
}{ data
},
\param{bool
}{ static
\_data=false
}}
103 Creates an image from given data with the given width and height. If
104 {\it static
\_data} is true, then wxImage will not delete the actual
105 image data in its destructor, otherwise it will free it by calling
108 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
110 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
112 Loads an image from a file.
114 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
116 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
118 Loads an image from an input stream.
120 \wxheading{Parameters
}
122 \docparam{width
}{Specifies the width of the image.
}
124 \docparam{height
}{Specifies the height of the image.
}
126 \docparam{name
}{Name of the file from which to load the image.
}
128 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
130 \docparam{type
}{May be one of the following:
134 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
135 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
136 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
137 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
138 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
139 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
140 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
141 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
142 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
143 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
144 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
145 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
148 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
150 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
151 This is only used by GIF, ICO and TIFF handlers. The default value (-
1) means
152 "choose the default image" and is interpreted as the first image (index=
0) by
153 the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.
}
157 Depending on how wxWindows has been configured, not all formats may be available.
159 Note: any handler other than BMP must be previously
160 initialized with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
161 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
163 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
164 hotspot for loaded cursor file:
166 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
167 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
173 \helpref{wxImage::LoadFile
}{wximageloadfile
}
175 \pythonnote{Constructors supported by wxPython are:
\par
176 \indented{2cm
}{\begin{twocollist
}
177 \twocolitem{{\bf wxImage(name, flag)
}}{Loads an image from a file
}
178 \twocolitem{{\bf wxNullImage()
}}{Create a null image (has no size or
180 \twocolitem{{\bf wxEmptyImage(width, height)
}}{Creates an empty image
182 \twocolitem{{\bf wxImageFromMime(name, mimetype
}}{Creates an image from
183 the given file of the given mimetype
}
184 \twocolitem{{\bf wxImageFromBitmap(bitmap)
}}{Creates an image from a
185 platform-dependent bitmap
}
189 \perlnote{Constructors supported by wxPerl are:
\par
191 \item{Wx::Image->new( bitmap )
}
192 \item{Wx::Image->new( width, height )
}
193 \item{Wx::Image->new( name, type )
}
194 \item{Wx::Image->new( name, mimetype )
}
198 \membersection{wxImage::
\destruct{wxImage
}}
200 \func{}{\destruct{wxImage
}}{\void}
204 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
206 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
208 Adds a handler to the end of the static list of format handlers.
210 \docparam{handler
}{A new image format handler object. There is usually only one instance
211 of a given handler class in an application session.
}
215 \helpref{wxImageHandler
}{wximagehandler
}
217 \func{bool
}{CanRead
}{\param{const wxString\&
}{ filename
}}
219 returns true if the current image handlers can read this file
221 \pythonnote{In wxPython this static method is named
{\tt wxImage
\_AddHandler}.
}
222 \membersection{wxImage::CleanUpHandlers
}
224 \func{static void
}{CleanUpHandlers
}{\void}
226 Deletes all image handlers.
228 This function is called by wxWindows on exit.
230 \membersection{wxImage::ComputeHistogram
}\label{wximagecomputehistogram
}
232 \constfunc{unsigned long
}{ComputeHistogram
}{\param{wxImageHistogram\&
}{histogram
}}
234 Computes the histogram of the image.
{\it histogram
} is a reference to
235 wxImageHistogram object. wxImageHistogram is a specialization of
236 \helpref{wxHashMap
}{wxhashmap
} "template" and is defined as follows:
239 class WXDLLEXPORT wxImageHistogramEntry
242 wxImageHistogramEntry() : index(
0), value(
0)
{}
247 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
248 wxIntegerHash, wxIntegerEqual,
252 \wxheading{Return value
}
254 Returns number of colours in the histogram.
256 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
258 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
260 Deprecated, use equivalent
\helpref{wxBitmap constructor
}{wxbitmapconstr
}
261 (which takes wxImage and depth as its arguments) instead.
263 \membersection{wxImage::ConvertToMono
}\label{wxbitmapconverttomono
}
265 \constfunc{wxImage
}{ConvertToMono
}{\param{unsigned char
}{ r
},
\param{unsigned char
}{ g
},
\param{unsigned char
}{ b
}}
267 Returns monochromatic version of the image. The returned image has white
268 colour where the original has
{\it (r,g,b)
} colour and black colour
271 \membersection{wxImage::Copy
}\label{wximagecopy
}
273 \constfunc{wxImage
}{Copy
}{\void}
275 Returns an identical copy of the image.
277 \membersection{wxImage::Create
}\label{wximagecreate
}
279 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{bool
}{ clear=true
}}
281 Creates a fresh image. If
{\it clear
} is true, the new image will be initialized to black.
282 Otherwise, the image data will be uninitialized.
284 \wxheading{Parameters
}
286 \docparam{width
}{The width of the image in pixels.
}
288 \docparam{height
}{The height of the image in pixels.
}
290 \wxheading{Return value
}
292 true if the call succeeded, false otherwise.
294 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
296 \func{bool
}{Destroy
}{\void}
298 Destroys the image data.
300 \membersection{wxImage::FindFirstUnusedColour
}\label{wximagefindfirstunusedcolour
}
302 \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}}
304 \wxheading{Parameters
}
306 \docparam{r,g,b
}{Pointers to variables to save the colour.
}
308 \docparam{startR,startG,startB
}{Initial values of the colour. Returned colour
309 will have RGB values equal to or greater than these.
}
311 Finds the first colour that is never used in the image. The search begins at
312 given initial colour and continues by increasing R, G and B components (in this
313 order) by
1 until an unused colour is found or the colour space exhausted.
315 \wxheading{Return value
}
317 Returns false if there is no unused colour left, true on success.
321 Note that this method involves computing the histogram, which is
322 computationally intensive operation.
324 \membersection{wxImage::FindHandler
}
326 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
328 Finds the handler with the given name.
330 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
332 Finds the handler associated with the given extension and type.
334 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
336 Finds the handler associated with the given image type.
338 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
340 Finds the handler associated with the given MIME type.
342 \docparam{name
}{The handler name.
}
344 \docparam{extension
}{The file extension, such as ``bmp".
}
346 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
348 \docparam{mimetype
}{MIME type.
}
350 \wxheading{Return value
}
352 A pointer to the handler if found, NULL otherwise.
356 \helpref{wxImageHandler
}{wximagehandler
}
358 \membersection{wxImage::GetAlpha
}\label{wximagegetalpha
}
360 \constfunc{unsigned char
}{GetAlpha
}{\param{int
}{ x
},
\param{int
}{ y
}}
362 Returns the alpha value for the given pixel. This function may only be called
363 for the images with alpha channel, use
\helpref{HasAlpha
}{wximagehasalpha
} to
366 The returned value is the
{\it opacity
} of the image, i.e. the value of $
0$
367 corresponds to the transparent pixels while the value of $
255$ -- to the opaque
370 \constfunc{unsigned char *
}{GetAlpha
}{\void}
372 Returns pointer to the array storing the alpha values for this image. This
373 pointer is
{\tt NULL
} for the images without the alpha channel. If the image
374 does have it, this pointer may be used to directly manipulate the alpha values
375 which are stored as the
\helpref{RGB
}{wximagegetdata
} ones.
377 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
379 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
381 Returns the blue intensity at the given coordinate.
383 \membersection{wxImage::GetData
}\label{wximagegetdata
}
385 \constfunc{unsigned char*
}{GetData
}{\void}
387 Returns the image data as an array. This is most often used when doing
388 direct image manipulation. The return value points to an array of
389 characters in RGBRGBRGB$
\ldots$ format in the top-to-bottom, left-to-right
390 order, that is the first RGB triplet corresponds to the pixel $(
0,
0)$, the
391 second one --- to $(
0,
1)$ and so on.
393 You should not delete the returned pointer nor pass it to
394 \helpref{wxImage::SetData
}{wximagesetdata
}.
396 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
398 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
400 Returns the green intensity at the given coordinate.
402 \membersection{wxImage::GetImageCount
}\label{wximagegetimagecount
}
404 \func{static int
}{GetImageCount
}{\param{const wxString\&
}{ filename
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
406 \func{static int
}{GetImageCount
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
408 If the image file contains more than one image and the image handler is capable
409 of retrieving these individually, this function will return the number of
412 \docparam{name
}{Name of the file to query.
}
414 \docparam{stream
}{Opened input stream with image data. Currently, the stream must support seeking.
}
416 \docparam{type
}{May be one of the following:
420 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
421 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
422 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
423 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
424 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
425 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
426 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
427 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
428 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
429 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
430 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
431 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
434 \wxheading{Return value
}
436 Number of available images. For most image handlers, this is
1 (exceptions
437 are TIFF and ICO formats).
439 \membersection{wxImage::GetHandlers
}
441 \func{static wxList\&
}{GetHandlers
}{\void}
443 Returns the static list of image format handlers.
447 \helpref{wxImageHandler
}{wximagehandler
}
449 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
451 \constfunc{int
}{GetHeight
}{\void}
453 Gets the height of the image in pixels.
455 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
457 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
459 Gets the blue value of the mask colour.
461 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
463 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
465 Gets the green value of the mask colour.
467 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
469 \constfunc{unsigned char
}{GetMaskRed
}{\void}
471 Gets the red value of the mask colour.
473 \membersection{wxImage::GetPalette
}\label{wximagegetpalette
}
475 \constfunc{const wxPalette\&
}{GetPalette
}{\void}
477 Returns the palette associated with the image. Currently the palette is only
478 used when converting to wxBitmap under Windows.
480 Eventually wxImage handlers will set the palette if one exists in the image file.
482 \membersection{wxImage::GetRed
}\label{wximagegetred
}
484 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
486 Returns the red intensity at the given coordinate.
488 \membersection{wxImage::GetSubImage
}\label{wximagegetsubimage
}
490 \constfunc{wxImage
}{GetSubImage
}{\param{const wxRect\&
}{ rect
}}
492 Returns a sub image of the current one as long as the rect belongs entirely to
495 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
497 \constfunc{int
}{GetWidth
}{\void}
499 Gets the width of the image in pixels.
503 \helpref{wxImage::GetHeight
}{wximagegetheight
}
505 \membersection{wxImage::HasAlpha
}\label{wximagehasalpha
}
507 \constfunc{bool
}{HasAlpha
}{\void}
509 Returns true if this image has alpha channel, false otherwise.
513 \helpref{GetAlpha
}{wximagegetalpha
},
\helpref{SetAlpha
}{wximagesetalpha
}
515 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
517 \constfunc{bool
}{HasMask
}{\void}
519 Returns true if there is a mask active, false otherwise.
521 \membersection{wxImage::GetOption
}\label{wximagegetoption
}
523 \constfunc{wxString
}{GetOption
}{\param{const wxString\&
}{ name
}}
525 Gets a user-defined option. The function is case-insensitive to
{\it name
}.
527 For example, when saving as a JPEG file, the option
{\bf quality
} is
528 used, which is a number between
0 and
100 (
0 is terrible,
100 is very good).
532 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
533 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
},
\rtfsp
534 \helpref{wxImage::HasOption
}{wximagehasoption
}
536 \membersection{wxImage::GetOptionInt
}\label{wximagegetoptionint
}
538 \constfunc{int
}{GetOptionInt
}{\param{const wxString\&
}{ name
}}
540 Gets a user-defined option as an integer. The function is case-insensitive to
{\it name
}.
544 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
545 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
546 \helpref{wxImage::HasOption
}{wximagehasoption
}
548 \membersection{wxImage::HasOption
}\label{wximagehasoption
}
550 \constfunc{bool
}{HasOption
}{\param{const wxString\&
}{ name
}}
552 Returns true if the given option is present. The function is case-insensitive to
{\it name
}.
556 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
557 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
558 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
}
560 \membersection{wxImage::InitStandardHandlers
}
562 \func{static void
}{InitStandardHandlers
}{\void}
564 Internal use only. Adds standard image format handlers. It only install BMP
565 for the time being, which is used by wxBitmap.
567 This function is called by wxWindows on startup, and shouldn't be called by
572 \helpref{wxImageHandler
}{wximagehandler
},
573 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
575 \membersection{wxImage::InsertHandler
}
577 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
579 Adds a handler at the start of the static list of format handlers.
581 \docparam{handler
}{A new image format handler object. There is usually only one instance
582 of a given handler class in an application session.
}
586 \helpref{wxImageHandler
}{wximagehandler
}
588 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
590 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
592 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
594 Loads an image from a file. If no handler type is provided, the library will
595 try to autodetect the format.
597 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
},
\param{int
}{ index = -
1}}
599 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
601 Loads an image from an input stream.
603 \wxheading{Parameters
}
605 \docparam{name
}{Name of the file from which to load the image.
}
607 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
609 \docparam{type
}{One of the following values:
613 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
614 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF image file.
}
615 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
616 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Load a PCX image file.
}
617 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
618 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Load a PNM image file.
}
619 \twocolitem{{\bf wxBITMAP
\_TYPE\_TIF}}{Load a TIFF image file.
}
620 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Load a XPM image file.
}
621 \twocolitem{{\bf wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
622 \twocolitem{{\bf wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
623 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
624 \twocolitem{{\bf wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
627 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
629 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
630 This is only used by GIF, ICO and TIFF handlers. The default value (-
1) means
631 "choose the default image" and is interpreted as the first image (index=
0) by
632 the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.
}
636 Depending on how wxWindows has been configured, not all formats may be available.
638 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
639 hotspot for loaded cursor file:
641 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
642 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
646 \wxheading{Return value
}
648 true if the operation succeeded, false otherwise. If the optional index parameter is out of range,
649 false is returned and a call to wxLogError() takes place.
653 \helpref{wxImage::SaveFile
}{wximagesavefile
}
655 \pythonnote{In place of a single overloaded method name, wxPython
656 implements the following methods:
\par
657 \indented{2cm
}{\begin{twocollist
}
658 \twocolitem{{\bf LoadFile(filename, type)
}}{Loads an image of the given
660 \twocolitem{{\bf LoadMimeFile(filename, mimetype)
}}{Loads an image of the given
661 mimetype from a file
}
665 \perlnote{Methods supported by wxPerl are:
\par
667 \item{bitmap->LoadFile( name, type )
}
668 \item{bitmap->LoadFile( name, mimetype )
}
673 \membersection{wxImage::Ok
}\label{wximageok
}
675 \constfunc{bool
}{Ok
}{\void}
677 Returns true if image data is present.
679 \membersection{wxImage::RemoveHandler
}
681 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
683 Finds the handler with the given name, and removes it. The handler
686 \docparam{name
}{The handler name.
}
688 \wxheading{Return value
}
690 true if the handler was found and removed, false otherwise.
694 \helpref{wxImageHandler
}{wximagehandler
}
696 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
698 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
700 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
702 Saves an image in the named file.
704 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
}}
706 Saves an image in the named file. File type is determined from the extension of the
707 file name. Note that this function may fail if the extension is not recognized! You
708 can use one of the forms above to save images to files with non-standard extensions.
710 \constfunc{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
712 \constfunc{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
714 Saves an image in the given stream.
716 \wxheading{Parameters
}
718 \docparam{name
}{Name of the file to save the image to.
}
720 \docparam{stream
}{Opened output stream to save the image to.
}
722 \docparam{type
}{Currently these types can be used:
726 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Save a BMP image file.
}
727 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
728 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
729 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Save a PCX image file (tries to save as
8-bit if possible, falls back to
24-bit otherwise).
}
730 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Save a PNM image file (as raw RGB always).
}
731 \twocolitem{{\bf wxBITMAP
\_TYPE\_TIFF}}{Save a TIFF image file.
}
732 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Save a XPM image file.
}
733 \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).
}
734 \twocolitem{{\bf wxBITMAP
\_TYPE\_CUR}}{Save a Windows cursor file (CUR).
}
737 \docparam{mimetype
}{MIME type.
}
739 \wxheading{Return value
}
741 true if the operation succeeded, false otherwise.
745 Depending on how wxWindows has been configured, not all formats may be available.
747 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to set the
748 hotspot before saving an image into a cursor file (default hotspot is in
749 the centre of the image):
751 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
752 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
758 \helpref{wxImage::LoadFile
}{wximageloadfile
}
760 \pythonnote{In place of a single overloaded method name, wxPython
761 implements the following methods:
\par
762 \indented{2cm
}{\begin{twocollist
}
763 \twocolitem{{\bf SaveFile(filename, type)
}}{Saves the image using the given
764 type to the named file
}
765 \twocolitem{{\bf SaveMimeFile(filename, mimetype)
}}{Saves the image using the given
766 mimetype to the named file
}
770 \perlnote{Methods supported by wxPerl are:
\par
772 \item{bitmap->SaveFile( name, type )
}
773 \item{bitmap->SaveFile( name, mimetype )
}
777 \membersection{wxImage::Mirror
}\label{wximagemirror
}
779 \constfunc{wxImage
}{Mirror
}{\param{bool
}{ horizontally = true
}}
781 Returns a mirrored copy of the image. The parameter
{\it horizontally
}
782 indicates the orientation.
784 \membersection{wxImage::Replace
}\label{wximagereplace
}
786 \func{void
}{Replace
}{\param{unsigned char
}{ r1
},
\param{unsigned char
}{ g1
},
\param{unsigned char
}{ b1
},
787 \param{unsigned char
}{ r2
},
\param{unsigned char
}{ g2
},
\param{unsigned char
}{ b2
}}
789 Replaces the colour specified by
{\it r1,g1,b1
} by the colour
{\it r2,g2,b2
}.
791 \membersection{wxImage::Rescale
}\label{wximagerescale
}
793 \func{wxImage \&
}{Rescale
}{\param{int
}{ width
},
\param{int
}{ height
}}
795 Changes the size of the image in-place: after a call to this function, the
796 image will have the given width and height.
798 Returns the (modified) image itself.
802 \helpref{Scale
}{wximagescale
}
804 \membersection{wxImage::Rotate
}\label{wximagerotate
}
806 \func{wxImage
}{Rotate
}{\param{double
}{ angle
},
\param{const wxPoint\&
}{rotationCentre
},
807 \param{bool
}{ interpolating = true
},
\param{wxPoint*
}{ offsetAfterRotation = NULL
}}
809 Rotates the image about the given point, by
{\it angle
} radians. Passing true
810 to
{\it interpolating
} results in better image quality, but is slower. If the
811 image has a mask, then the mask colour is used for the uncovered pixels in the
812 rotated image background. Else, black (rgb
0,
0,
0) will be used.
814 Returns the rotated image, leaving this image intact.
816 \membersection{wxImage::Rotate90
}\label{wximagerotate90
}
818 \constfunc{wxImage
}{Rotate90
}{\param{bool
}{ clockwise = true
}}
820 Returns a copy of the image rotated
90 degrees in the direction
821 indicated by
{\it clockwise
}.
823 \membersection{wxImage::Scale
}\label{wximagescale
}
825 \constfunc{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
827 Returns a scaled version of the image. This is also useful for
828 scaling bitmaps in general as the only other way to scale bitmaps
829 is to blit a wxMemoryDC into another wxMemoryDC.
831 It may be mentioned that the GTK port uses this function internally
832 to scale bitmaps when using mapping modes in wxDC.
837 // get the bitmap from somewhere
840 // rescale it to have size of
32*
32
841 if ( bmp.GetWidth() !=
32 || bmp.GetHeight() !=
32 )
843 wxImage image = bmp.ConvertToImage();
844 bmp = wxBitmap(image.Scale(
32,
32));
846 // another possibility:
847 image.Rescale(
32,
32);
855 \helpref{Rescale
}{wximagerescale
}
857 \membersection{wxImage::SetAlpha
}\label{wximagesetalpha
}
859 \func{void
}{SetAlpha
}{\param{unsigned char *
}{alpha =
{\tt NULL
}}}
861 This function is similar to
\helpref{SetData
}{wximagesetdata
} and has similar
862 restrictions. The pointer passed to it may however be
{\tt NULL
} in which case
863 the function will allocate the alpha array internally -- this is useful to add
864 alpha channel data to an image which doesn't have any. If the pointer is not
865 {\tt NULL
}, it must have one byte for each image pixel and be allocated with
866 {\tt malloc()
}. wxImage takes ownership of the pointer and will free it.
868 \func{void
}{SetAlpha
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{alpha
}}
870 Sets the alpha value for the given pixel. This function should only be called
871 if the image has alpha channel data, use
\helpref{HasAlpha
}{wximagehasalpha
} to
874 \membersection{wxImage::SetData
}\label{wximagesetdata
}
876 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
878 Sets the image data without performing checks. The data given must have
879 the size (width*height*
3) or results will be unexpected. Don't use this
880 method if you aren't sure you know what you are doing.
882 The data must have been allocated with
{\tt malloc()
},
{\large {\bf NOT
}} with
885 After this call the pointer to the data is owned by the wxImage object,
886 that will be responsible for deleting it.
887 Do not pass to this function a pointer obtained through
888 \helpref{wxImage::GetData
}{wximagegetdata
}.
890 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
892 \func{void
}{SetMask
}{\param{bool
}{ hasMask = true
}}
894 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
896 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
898 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{green
},
\param{unsigned char
}{blue
}}
900 Sets the mask colour for this image (and tells the image to use the mask).
902 \membersection{wxImage::SetMaskFromImage
}\label{wximagesetmaskfromimage
}
904 \func{bool
}{SetMaskFromImage
}{\param{const wxImage\&
}{ mask
},
\param{unsigned char
}{ mr
},
\param{unsigned char
}{ mg
},
\param{unsigned char
}{ mb
}}
906 \wxheading{Parameters
}
908 \docparam{mask
}{The mask image to extract mask shape from. Must have same dimensions as the image.
}
910 \docparam{mr,mg,mb
}{RGB value of pixels in
{\it mask
} that will be used to create the mask.
}
912 Sets image's mask so that the pixels that have RGB value of
{\it mr,mg,mb
}
913 in
{\it mask
} will be masked in the image. This is done by first finding an
914 unused colour in the image, setting this colour as the mask colour and then
915 using this colour to draw all pixels in the image who corresponding pixel
916 in
{\it mask
} has given RGB value.
918 \wxheading{Return value
}
920 Returns false if
{\it mask
} does not have same dimensions as the image or if
921 there is no unused colour left. Returns true if the mask was successfully
926 Note that this method involves computing the histogram, which is
927 computationally intensive operation.
929 \membersection{wxImage::SetOption
}\label{wximagesetoption
}
931 \func{void
}{SetOption
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ value
}}
933 \func{void
}{SetOption
}{\param{const wxString\&
}{ name
},
\param{int
}{ value
}}
935 Sets a user-defined option. The function is case-insensitive to
{\it name
}.
937 For example, when saving as a JPEG file, the option
{\bf quality
} is
938 used, which is a number between
0 and
100 (
0 is terrible,
100 is very good).
942 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
943 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
},
\rtfsp
944 \helpref{wxImage::HasOption
}{wximagehasoption
}
946 \membersection{wxImage::SetPalette
}\label{wximagesetpalette
}
948 \func{void
}{SetPalette
}{\param{const wxPalette\&
}{ palette
}}
950 Associates a palette with the image. The palette may be used when converting
951 wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).
953 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
955 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{green
},
\param{unsigned char
}{blue
}}
957 Sets the pixel at the given coordinate. This routine performs bounds-checks
958 for the coordinate so it can be considered a safe way to manipulate the
959 data, but in some cases this might be too slow so that the data will have to
960 be set directly. In that case you will have to get access to the image data
961 using the
\helpref{GetData
}{wximagegetdata
} method.
963 \membersection{wxImage::operator $=$
}
965 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
967 Assignment operator. This operator does not copy any data, but instead
968 passes a pointer to the data in
{\it image
} and increments a reference
969 counter. It is a fast operation.
971 \wxheading{Parameters
}
973 \docparam{image
}{Image to assign.
}
975 \wxheading{Return value
}
977 Returns 'this' object.
979 \membersection{wxImage::operator $==$
}
981 \constfunc{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
983 Equality operator. This operator tests whether the internal data pointers are
986 \wxheading{Parameters
}
988 \docparam{image
}{Image to compare with 'this'
}
990 \wxheading{Return value
}
992 Returns true if the images were effectively equal, false otherwise.
994 \membersection{wxImage::operator $!=$
}
996 \constfunc{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
998 Inequality operator. This operator tests whether the internal data pointers are
999 unequal (a fast test).
1001 \wxheading{Parameters
}
1003 \docparam{image
}{Image to compare with 'this'
}
1005 \wxheading{Return value
}
1007 Returns true if the images were unequal, false otherwise.
1009 \section{\class{wxImageHandler
}}\label{wximagehandler
}
1011 This is the base class for implementing image file loading/saving, and image creation from data.
1012 It is used within wxImage and is not normally seen by the application.
1014 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
1015 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
1016 application initialisation.
1018 \wxheading{Note (Legal Issue)
}
1020 This software is based in part on the work of the Independent JPEG Group.
1022 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
1025 \wxheading{Derived from
}
1027 \helpref{wxObject
}{wxobject
}
1029 \wxheading{Include files
}
1033 \wxheading{See also
}
1035 \helpref{wxImage
}{wximage
},
1036 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
1038 \latexignore{\rtfignore{\wxheading{Members
}}}
1040 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
1042 \func{}{wxImageHandler
}{\void}
1044 Default constructor. In your own default constructor, initialise the members
1045 m
\_name, m
\_extension and m
\_type.
1047 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
1049 \func{}{\destruct{wxImageHandler
}}{\void}
1051 Destroys the wxImageHandler object.
1053 \membersection{wxImageHandler::GetName
}
1055 \constfunc{wxString
}{GetName
}{\void}
1057 Gets the name of this handler.
1059 \membersection{wxImageHandler::GetExtension
}
1061 \constfunc{wxString
}{GetExtension
}{\void}
1063 Gets the file extension associated with this handler.
1065 \membersection{wxImageHandler::GetImageCount
}\label{wximagehandlergetimagecount
}
1067 \func{int
}{GetImageCount
}{\param{wxInputStream\&
}{ stream
}}
1069 If the image file contains more than one image and the image handler is capable
1070 of retrieving these individually, this function will return the number of
1073 \docparam{stream
}{Opened input stream for reading image data. Currently, the stream must support seeking.
}
1075 \wxheading{Return value
}
1077 Number of available images. For most image handlers, this is
1 (exceptions
1078 are TIFF and ICO formats).
1080 \membersection{wxImageHandler::GetType
}
1082 \constfunc{long
}{GetType
}{\void}
1084 Gets the image type associated with this handler.
1086 \membersection{wxImageHandler::GetMimeType
}
1088 \constfunc{wxString
}{GetMimeType
}{\void}
1090 Gets the MIME type associated with this handler.
1092 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
1094 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
},
\param{bool
}{ verbose=true
},
\param{int
}{ index=
0}}
1096 Loads a image from a stream, putting the resulting data into
{\it image
}. If the image file contains
1097 more than one image and the image handler is capable of retrieving these individually,
{\it index
}
1098 indicates which image to read from the stream.
1100 \wxheading{Parameters
}
1102 \docparam{image
}{The image object which is to be affected by this operation.
}
1104 \docparam{stream
}{Opened input stream for reading image data.
}
1106 \docparam{verbose
}{If set to true, errors reported by the image handler will produce wxLogMessages.
}
1108 \docparam{index
}{The index of the image in the file (starting from zero).
}
1110 \wxheading{Return value
}
1112 true if the operation succeeded, false otherwise.
1114 \wxheading{See also
}
1116 \helpref{wxImage::LoadFile
}{wximageloadfile
},
1117 \helpref{wxImage::SaveFile
}{wximagesavefile
},
1118 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
1120 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
1122 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
1124 Saves a image in the output stream.
1126 \wxheading{Parameters
}
1128 \docparam{image
}{The image object which is to be affected by this operation.
}
1130 \docparam{stream
}{Opened output stream for writing the data.
}
1132 \wxheading{Return value
}
1134 true if the operation succeeded, false otherwise.
1136 \wxheading{See also
}
1138 \helpref{wxImage::LoadFile
}{wximageloadfile
},
1139 \helpref{wxImage::SaveFile
}{wximagesavefile
},
1140 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
1142 \membersection{wxImageHandler::SetName
}
1144 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
1146 Sets the handler name.
1148 \wxheading{Parameters
}
1150 \docparam{name
}{Handler name.
}
1152 \membersection{wxImageHandler::SetExtension
}
1154 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
1156 Sets the handler extension.
1158 \wxheading{Parameters
}
1160 \docparam{extension
}{Handler extension.
}
1162 \membersection{wxImageHandler::SetMimeType
}\label{wximagehandlersetmimetype
}
1164 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
1166 Sets the handler MIME type.
1168 \wxheading{Parameters
}
1170 \docparam{mimename
}{Handler MIME type.
}
1172 \membersection{wxImageHandler::SetType
}
1174 \func{void
}{SetType
}{\param{long
}{type
}}
1176 Sets the handler type.
1178 \wxheading{Parameters
}
1180 \docparam{name
}{Handler type.
}