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 appropiate
22 handler with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
23 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
27 \twocolitem{\indexit{wxBMPHandler
}}{Only for loading, 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{wxXPMHandler
}}{For loading and saving.
}
35 \twocolitem{\indexit{wxICOHandler
}}{For loading and saving.
}
36 \twocolitem{\indexit{wxCURHandler
}}{For loading and saving.
}
37 \twocolitem{\indexit{wxANIHandler
}}{For loading and saving.
}
40 When saving in PCX format,
{\bf wxPCXHandler
} will count the number of
41 different colours in the image; if there are
256 or less colours, it will
42 save as
8 bit, else it will save as
24 bit.
44 Loading PNMs only works for ASCII or raw RGB images. When saving in
45 PNM format,
{\bf wxPNMHandler
} will always save as raw RGB.
47 \wxheading{Derived from
}
49 \helpref{wxObject
}{wxobject
}
51 \wxheading{Include files
}
57 \helpref{wxBitmap
}{wxbitmap
},
58 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
60 \latexignore{\rtfignore{\wxheading{Members
}}}
62 \membersection{wxImage::wxImage
}\label{wximageconstr
}
64 \func{}{wxImage
}{\void}
68 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
72 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
74 (Deprecated form, use
\helpref{wxBitmap::ConvertToImage
}{wxbitmapconverttoimage
}
75 instead.) Constructs an image from a platform-dependent bitmap. This preserves
76 mask information so that bitmaps and images can be converted back
77 and forth without loss in that respect.
79 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
81 Creates an image with the given width and height.
83 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{unsigned char*
}{ data
},
\param{bool
}{ static
\_data=FALSE
}}
85 Creates an image from given data with the given width and height. If
86 {\it static
\_data} is TRUE, then wxImage will not delete the actual
87 image data in its destructor, otherwise it will free it by calling
90 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
92 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
94 Loads an image from a file.
96 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
98 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
100 Loads an image from an input stream.
102 \wxheading{Parameters
}
104 \docparam{width
}{Specifies the width of the image.
}
106 \docparam{height
}{Specifies the height of the image.
}
108 \docparam{name
}{Name of the file from which to load the image.
}
110 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
112 \docparam{type
}{May be one of the following:
116 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
117 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
118 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
119 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
120 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
121 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
122 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
123 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
124 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
125 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
126 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
127 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
130 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
132 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
133 This is only used by ICO and TIFF handlers. The default value (-
1) means
134 "choose the default image" and is interpreted as the first image (index=
0) by
135 the TIFF handler and as the largest and most colourful one by the ICO handler.
}
139 Depending on how wxWindows has been configured, not all formats may be available.
141 Note: any handler other than BMP must be previously
142 initialized with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
143 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
145 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
146 hotspot for loaded cursor file:
148 int hotspot_x = image.GetOptionInt(wxCUR_HOTSPOT_X);
149 int hotspot_y = image.GetOptionInt(wxCUR_HOTSPOT_Y);
155 \helpref{wxImage::LoadFile
}{wximageloadfile
}
157 \pythonnote{Constructors supported by wxPython are:
\par
158 \indented{2cm
}{\begin{twocollist
}
159 \twocolitem{{\bf wxImage(name, flag)
}}{Loads an image from a file
}
160 \twocolitem{{\bf wxNullImage()
}}{Create a null image (has no size or
162 \twocolitem{{\bf wxEmptyImage(width, height)
}}{Creates an empty image
164 \twocolitem{{\bf wxImageFromMime(name, mimetype
}}{Creates an image from
165 the given file of the given mimetype
}
166 \twocolitem{{\bf wxImageFromBitmap(bitmap)
}}{Creates an image from a
167 platform-dependent bitmap
}
171 \perlnote{Constructors supported by wxPerl are:
\par
173 \item{Wx::Image->new( bitmap )
}
174 \item{Wx::Image->new( width, height )
}
175 \item{Wx::Image->new( name, type )
}
176 \item{Wx::Image->new( name, mimetype )
}
180 \membersection{wxImage::
\destruct{wxImage
}}
182 \func{}{\destruct{wxImage
}}{\void}
186 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
188 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
190 Adds a handler to the end of the static list of format handlers.
192 \docparam{handler
}{A new image format handler object. There is usually only one instance
193 of a given handler class in an application session.
}
197 \helpref{wxImageHandler
}{wximagehandler
}
199 \pythonnote{In wxPython this static method is named
{\tt wxImage
\_AddHandler}.
}
200 \membersection{wxImage::CleanUpHandlers
}
202 \func{static void
}{CleanUpHandlers
}{\void}
204 Deletes all image handlers.
206 This function is called by wxWindows on exit.
208 \membersection{wxImage::ComputeHistogram
}\label{wximagecomputehistogram
}
210 \constfunc{unsigned long
}{ComputeHistogram
}{\param{wxImageHistogram\&
}{histogram
}}
212 Computes the histogram of the image.
{\it histogram
} is a reference to
213 wxImageHistogram object. wxImageHistogram is a specialization of
214 \helpref{wxHashMap
}{wxhashmap
} "template" and is defined as follows:
217 class WXDLLEXPORT wxImageHistogramEntry
220 wxImageHistogramEntry() : index(
0), value(
0)
{}
225 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
226 wxIntegerHash, wxIntegerEqual,
230 \wxheading{Return value
}
232 Returns number of colours in the histogram.
234 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
236 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
238 Deprecated, use equivalent
\helpref{wxBitmap constructor
}{wxbitmapconstr
}
239 (which takes wxImage and depth as its arguments) instead.
241 \membersection{wxImage::ConvertToMono
}\label{wxbitmapconverttomono
}
243 \constfunc{wxImage
}{ConvertToMono
}{\param{unsigned char
}{ r
},
\param{unsigned char
}{ g
},
\param{unsigned char
}{ b
}}
245 Returns monochromatic version of the image. The returned image has white
246 colour where the original has
{\it (r,g,b)
} colour and black colour
249 \membersection{wxImage::Copy
}\label{wximagecopy
}
251 \constfunc{wxImage
}{Copy
}{\void}
253 Returns an identical copy of the image.
255 \membersection{wxImage::Create
}\label{wximagecreate
}
257 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
259 Creates a fresh image.
261 \wxheading{Parameters
}
263 \docparam{width
}{The width of the image in pixels.
}
265 \docparam{height
}{The height of the image in pixels.
}
267 \wxheading{Return value
}
269 TRUE if the call succeeded, FALSE otherwise.
271 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
273 \func{bool
}{Destroy
}{\void}
275 Destroys the image data.
277 \membersection{wxImage::FindFirstUnusedColour
}\label{wximagefindfirstunusedcolour
}
279 \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}}
281 \wxheading{Parameters
}
283 \docparam{r,g,b
}{Pointers to variables to save the colour.
}
285 \docparam{startR,startG,startB
}{Initial values of the colour. Returned colour
286 will have RGB values equal to or greater than these.
}
288 Finds the first colour that is never used in the image. The search begins at
289 given initial colour and continues by increasing R, G and B components (in this
290 order) by
1 until an unused colour is found or the colour space exhausted.
292 \wxheading{Return value
}
294 Returns FALSE if there is no unused colour left, TRUE on success.
298 Note that this method involves computing the histogram, which is
299 computationally intensive operation.
301 \membersection{wxImage::FindHandler
}
303 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
305 Finds the handler with the given name.
307 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
309 Finds the handler associated with the given extension and type.
311 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
313 Finds the handler associated with the given image type.
315 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
317 Finds the handler associated with the given MIME type.
319 \docparam{name
}{The handler name.
}
321 \docparam{extension
}{The file extension, such as ``bmp".
}
323 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
325 \docparam{mimetype
}{MIME type.
}
327 \wxheading{Return value
}
329 A pointer to the handler if found, NULL otherwise.
333 \helpref{wxImageHandler
}{wximagehandler
}
335 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
337 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
339 Returns the blue intensity at the given coordinate.
341 \membersection{wxImage::GetData
}\label{wximagegetdata
}
343 \constfunc{unsigned char*
}{GetData
}{\void}
345 Returns the image data as an array. This is most often used when doing
346 direct image manipulation. The return value points to an array of
347 chararcters in RGBGBRGB... format.
349 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
351 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
353 Returns the green intensity at the given coordinate.
355 \membersection{wxImage::GetImageCount
}\label{wximagegetimagecount
}
357 \func{static int
}{GetImageCount
}{\param{const wxString\&
}{ filename
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
359 \func{static int
}{GetImageCount
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
361 If the image file contains more than one image and the image handler is capable
362 of retrieving these individually, this function will return the number of
365 \docparam{name
}{Name of the file to query.
}
367 \docparam{stream
}{Opened input stream with image data. Currently, the stream must support seeking.
}
369 \docparam{type
}{May be one of the following:
373 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
374 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
375 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
376 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
377 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
378 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
379 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
380 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
381 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
382 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
383 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
384 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
387 \wxheading{Return value
}
389 Number of available images. For most image handlers, this is
1 (exceptions
390 are TIFF and ICO formats).
392 \membersection{wxImage::GetRed
}\label{wximagegetred
}
394 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
396 Returns the red intensity at the given coordinate.
398 \membersection{wxImage::GetHandlers
}
400 \func{static wxList\&
}{GetHandlers
}{\void}
402 Returns the static list of image format handlers.
406 \helpref{wxImageHandler
}{wximagehandler
}
408 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
410 \constfunc{int
}{GetHeight
}{\void}
412 Gets the height of the image in pixels.
414 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
416 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
418 Gets the blue value of the mask colour.
420 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
422 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
424 Gets the green value of the mask colour.
426 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
428 \constfunc{unsigned char
}{GetMaskRed
}{\void}
430 Gets the red value of the mask colour.
432 \membersection{wxImage::GetPalette
}\label{wximagegetpalette
}
434 \constfunc{const wxPalette\&
}{GetPalette
}{\void}
436 Returns the palette associated with the image. Currently the palette is only
437 used when converting to wxBitmap under Windows.
439 Eventually wxImage handlers will set the palette if one exists in the image file.
441 \membersection{wxImage::GetSubImage
}\label{wximagegetsubimage
}
443 \constfunc{wxImage
}{GetSubImage
}{\param{const wxRect\&
}{ rect
}}
445 Returns a sub image of the current one as long as the rect belongs entirely to
448 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
450 \constfunc{int
}{GetWidth
}{\void}
452 Gets the width of the image in pixels.
456 \helpref{wxImage::GetHeight
}{wximagegetheight
}
458 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
460 \constfunc{bool
}{HasMask
}{\void}
462 Returns TRUE if there is a mask active, FALSE otherwise.
464 \membersection{wxImage::GetOption
}\label{wximagegetoption
}
466 \constfunc{wxString
}{GetOption
}{\param{const wxString\&
}{ name
}}
468 Gets a user-defined option. The function is case-insensitive to
{\it name
}.
470 For example, when saving as a JPEG file, the option
{\bf quality
} is
471 used, which is a number between
0 and
100 (
0 is terrible,
100 is very good).
475 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
476 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
},
\rtfsp
477 \helpref{wxImage::HasOption
}{wximagehasoption
}
479 \membersection{wxImage::GetOptionInt
}\label{wximagegetoptionint
}
481 \constfunc{int
}{GetOptionInt
}{\param{const wxString\&
}{ name
}}
483 Gets a user-defined option as an integer. The function is case-insensitive to
{\it name
}.
487 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
488 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
489 \helpref{wxImage::HasOption
}{wximagehasoption
}
491 \membersection{wxImage::HasOption
}\label{wximagehasoption
}
493 \constfunc{bool
}{HasOption
}{\param{const wxString\&
}{ name
}}
495 Returns TRUE if the given option is present. The function is case-insensitive to
{\it name
}.
499 \helpref{wxImage::SetOption
}{wximagesetoption
},
\rtfsp
500 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
501 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
}
503 \membersection{wxImage::InitStandardHandlers
}
505 \func{static void
}{InitStandardHandlers
}{\void}
507 Internal use only. Adds standard image format handlers. It only install BMP
508 for the time being, which is used by wxBitmap.
510 This function is called by wxWindows on startup, and shouldn't be called by
515 \helpref{wxImageHandler
}{wximagehandler
},
516 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
518 \membersection{wxImage::InsertHandler
}
520 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
522 Adds a handler at the start of the static list of format handlers.
524 \docparam{handler
}{A new image format handler object. There is usually only one instance
525 of a given handler class in an application session.
}
529 \helpref{wxImageHandler
}{wximagehandler
}
531 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
533 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
535 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
537 Loads an image from a file. If no handler type is provided, the library will
538 try to autodetect the format.
540 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
},
\param{int
}{ index = -
1}}
542 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
544 Loads an image from an input stream.
546 \wxheading{Parameters
}
548 \docparam{name
}{Name of the file from which to load the image.
}
550 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
552 \docparam{type
}{One of the following values:
556 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
557 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF image file.
}
558 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
559 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Load a PCX image file.
}
560 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
561 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Load a PNM image file.
}
562 \twocolitem{{\bf wxBITMAP
\_TYPE\_TIF}}{Load a TIFF image file.
}
563 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Load a XPM image file.
}
564 \twocolitem{{\bf wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
565 \twocolitem{{\bf wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
566 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
567 \twocolitem{{\bf wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
570 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
572 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
573 This is only used by ICO and TIFF handlers. The default value (-
1) means
574 "choose the default image" and is interpreted as the first image (index=
0) by
575 the TIFF handler and as the largest and most colourful one by the ICO handler.
}
579 Depending on how wxWindows has been configured, not all formats may be available.
581 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
582 hotspot for loaded cursor file:
584 int hotspot_x = image.GetOptionInt(wxCUR_HOTSPOT_X);
585 int hotspot_y = image.GetOptionInt(wxCUR_HOTSPOT_Y);
589 \wxheading{Return value
}
591 TRUE if the operation succeeded, FALSE otherwise.
595 \helpref{wxImage::SaveFile
}{wximagesavefile
}
597 \pythonnote{In place of a single overloaded method name, wxPython
598 implements the following methods:
\par
599 \indented{2cm
}{\begin{twocollist
}
600 \twocolitem{{\bf LoadFile(filename, type)
}}{Loads an image of the given
602 \twocolitem{{\bf LoadMimeFile(filename, mimetype)
}}{Loads an image of the given
603 mimetype from a file
}
607 \perlnote{Methods supported by wxPerl are:
\par
609 \item{bitmap->LoadFile( name, type )
}
610 \item{bitmap->LoadFile( name, mimetype )
}
615 \membersection{wxImage::Ok
}\label{wximageok
}
617 \constfunc{bool
}{Ok
}{\void}
619 Returns TRUE if image data is present.
621 \membersection{wxImage::RemoveHandler
}
623 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
625 Finds the handler with the given name, and removes it. The handler
628 \docparam{name
}{The handler name.
}
630 \wxheading{Return value
}
632 TRUE if the handler was found and removed, FALSE otherwise.
636 \helpref{wxImageHandler
}{wximagehandler
}
638 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
640 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
642 \constfunc{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
644 Saves a image in the named file.
646 \constfunc{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
648 \constfunc{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
650 Saves a image in the given stream.
652 \wxheading{Parameters
}
654 \docparam{name
}{Name of the file to save the image to.
}
656 \docparam{stream
}{Opened output stream to save the image to.
}
658 \docparam{type
}{Currently three types can be used:
662 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
663 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
664 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Save a PCX image file (tries to save as
8-bit if possible, falls back to
24-bit otherwise).
}
665 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Save a PNM image file (as raw RGB always).
}
666 \twocolitem{{\bf wxBITMAP
\_TYPE\_TIFF}}{Save a TIFF image file.
}
667 \twocolitem{{\bf wxBITMAP
\_TYPE\_XPM}}{Save a XPM image file.
}
668 \twocolitem{{\bf wxBITMAP
\_TYPE\_ICO}}{Save a ICO image file.
}
669 \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).
}
670 \twocolitem{{\bf wxBITMAP
\_TYPE\_CUR}}{Save a Windows cursor file (CUR).
}
673 \docparam{mimetype
}{MIME type.
}
675 \wxheading{Return value
}
677 TRUE if the operation succeeded, FALSE otherwise.
681 Depending on how wxWindows has been configured, not all formats may be available.
683 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to set the
684 hotspot before saving an image into a cursor file (default hotspot is in
685 the centre of the image):
687 image.SetOption(wxCUR_HOTSPOT_X, hotspotX);
688 image.SetOption(wxCUR_HOTSPOT_Y, hotspotY);
694 \helpref{wxImage::LoadFile
}{wximageloadfile
}
696 \pythonnote{In place of a single overloaded method name, wxPython
697 implements the following methods:
\par
698 \indented{2cm
}{\begin{twocollist
}
699 \twocolitem{{\bf SaveFile(filename, type)
}}{Saves the image using the given
700 type to the named file
}
701 \twocolitem{{\bf SaveMimeFile(filename, mimetype)
}}{Saves the image using the given
702 mimetype to the named file
}
706 \perlnote{Methods supported by wxPerl are:
\par
708 \item{bitmap->SaveFile( name, type )
}
709 \item{bitmap->SaveFile( name, mimetype )
}
713 \membersection{wxImage::Mirror
}\label{wximagemirror
}
715 \constfunc{wxImage
}{Mirror
}{\param{bool
}{ horizontally = TRUE
}}
717 Returns a mirrored copy of the image. The parameter
{\it horizontally
}
718 indicates the orientation.
720 \membersection{wxImage::Replace
}\label{wximagereplace
}
722 \func{void
}{Replace
}{\param{unsigned char
}{ r1
},
\param{unsigned char
}{ g1
},
\param{unsigned char
}{ b1
},
723 \param{unsigned char
}{ r2
},
\param{unsigned char
}{ g2
},
\param{unsigned char
}{ b2
}}
725 Replaces the colour specified by
{\it r1,g1,b1
} by the colour
{\it r2,g2,b2
}.
727 \membersection{wxImage::Rescale
}\label{wximagerescale
}
729 \func{wxImage \&
}{Rescale
}{\param{int
}{ width
},
\param{int
}{ height
}}
731 Changes the size of the image in-place: after a call to this function, the
732 image will have the given width and height.
734 Returns the (modified) image itself.
738 \helpref{Scale
}{wximagescale
}
740 \membersection{wxImage::Rotate
}\label{wximagerotate
}
742 \func{wxImage
}{Rotate
}{\param{double
}{ angle
},
\param{const wxPoint\&
}{rotationCentre
},
743 \param{bool
}{ interpolating = TRUE
},
\param{wxPoint*
}{ offsetAfterRotation = NULL
}}
745 Rotates the image about the given point, by
{\it angle
} radians. Passing TRUE
746 to
{\it interpolating
} results in better image quality, but is slower. If the
747 image has a mask, then the mask colour is used for the uncovered pixels in the
748 rotated image background. Else, black (rgb
0,
0,
0) will be used.
750 Returns the rotated image, leaving this image intact.
752 \membersection{wxImage::Rotate90
}\label{wximagerotate90
}
754 \constfunc{wxImage
}{Rotate90
}{\param{bool
}{ clockwise = TRUE
}}
756 Returns a copy of the image rotated
90 degrees in the direction
757 indicated by
{\it clockwise
}.
759 \membersection{wxImage::Scale
}\label{wximagescale
}
761 \constfunc{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
763 Returns a scaled version of the image. This is also useful for
764 scaling bitmaps in general as the only other way to scale bitmaps
765 is to blit a wxMemoryDC into another wxMemoryDC.
767 It may be mentioned that the GTK port uses this function internally
768 to scale bitmaps when using mapping modes in wxDC.
773 // get the bitmap from somewhere
776 // rescale it to have size of
32*
32
777 if ( bmp.GetWidth() !=
32 || bmp.GetHeight() !=
32 )
780 bmp = wxBitmap(image.Scale(
32,
32));
782 // another possibility:
783 image.Rescale(
32,
32);
791 \helpref{Rescale
}{wximagerescale
}
793 \membersection{wxImage::SetData
}\label{wximagesetdata
}
795 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
797 Sets the image data without performing checks. The data given must have
798 the size (width*height*
3) or results will be unexpected. Don't use this
799 method if you aren't sure you know what you are doing.
801 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
803 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
805 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
807 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
809 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
811 Sets the mask colour for this image (and tells the image to use the mask).
813 \membersection{wxImage::SetMaskFromImage
}\label{wximagesetmaskfromimage
}
815 \func{bool
}{SetMaskFromImage
}{\param{const wxImage\&
}{ mask
},
\param{unsigned char
}{ mr
},
\param{unsigned char
}{ mg
},
\param{unsigned char
}{ mb
}}
817 \wxheading{Parameters
}
819 \docparam{mask
}{The mask image to extract mask shape from. Must have same dimensions as the image.
}
821 \docparam{mr,mg,mb
}{RGB value of pixels in
{\it mask
} that will be used to create the mask.
}
823 Sets image's mask so that the pixels that have RGB value of
{\it mr,mg,mb
}
824 in
{\it mask
} will be masked in the image. This is done by first finding an
825 unused colour in the image, setting this colour as the mask colour and then
826 using this colour to draw all pixels in the image who corresponding pixel
827 in
{\it mask
} has given RGB value.
829 \wxheading{Return value
}
831 Returns FALSE if
{\it mask
} does not have same dimensions as the image or if
832 there is no unused colour left. Returns TRUE if the mask was successfully
837 Note that this method involves computing the histogram, which is
838 computationally intensive operation.
840 \membersection{wxImage::SetOption
}\label{wximagesetoption
}
842 \func{void
}{SetOption
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ value
}}
844 \func{void
}{SetOption
}{\param{const wxString\&
}{ name
},
\param{int
}{ value
}}
846 Sets a user-defined option. The function is case-insensitive to
{\it name
}.
848 For example, when saving as a JPEG file, the option
{\bf quality
} is
849 used, which is a number between
0 and
100 (
0 is terrible,
100 is very good).
853 \helpref{wxImage::GetOption
}{wximagegetoption
},
\rtfsp
854 \helpref{wxImage::GetOptionInt
}{wximagegetoptionint
},
\rtfsp
855 \helpref{wxImage::HasOption
}{wximagehasoption
}
857 \membersection{wxImage::SetPalette
}\label{wximagesetpalette
}
859 \func{void
}{SetPalette
}{\param{const wxPalette\&
}{ palette
}}
861 Associates a palette with the image. The palette may be used when converting
862 wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).
864 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
866 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{green
},
\param{unsigned char
}{blue
}}
868 Sets the pixel at the given coordinate. This routine performs bounds-checks
869 for the coordinate so it can be considered a safe way to manipulate the
870 data, but in some cases this might be too slow so that the data will have to
871 be set directly. In that case you will have to get access to the image data
872 using the
\helpref{GetData
}{wximagegetdata
} method.
874 \membersection{wxImage::operator $=$
}
876 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
878 Assignment operator. This operator does not copy any data, but instead
879 passes a pointer to the data in
{\it image
} and increments a reference
880 counter. It is a fast operation.
882 \wxheading{Parameters
}
884 \docparam{image
}{Image to assign.
}
886 \wxheading{Return value
}
888 Returns 'this' object.
890 \membersection{wxImage::operator $==$
}
892 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
894 Equality operator. This operator tests whether the internal data pointers are
897 \wxheading{Parameters
}
899 \docparam{image
}{Image to compare with 'this'
}
901 \wxheading{Return value
}
903 Returns TRUE if the images were effectively equal, FALSE otherwise.
905 \membersection{wxImage::operator $!=$
}
907 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
909 Inequality operator. This operator tests whether the internal data pointers are
910 unequal (a fast test).
912 \wxheading{Parameters
}
914 \docparam{image
}{Image to compare with 'this'
}
916 \wxheading{Return value
}
918 Returns TRUE if the images were unequal, FALSE otherwise.
920 \section{\class{wxImageHandler
}}\label{wximagehandler
}
922 This is the base class for implementing image file loading/saving, and image creation from data.
923 It is used within wxImage and is not normally seen by the application.
925 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
926 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
927 application initialisation.
929 \wxheading{Note (Legal Issue)
}
931 This software is based in part on the work of the Independent JPEG Group.
933 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
936 \wxheading{Derived from
}
938 \helpref{wxObject
}{wxobject
}
940 \wxheading{Include files
}
946 \helpref{wxImage
}{wximage
},
947 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
949 \latexignore{\rtfignore{\wxheading{Members
}}}
951 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
953 \func{}{wxImageHandler
}{\void}
955 Default constructor. In your own default constructor, initialise the members
956 m
\_name, m
\_extension and m
\_type.
958 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
960 \func{}{\destruct{wxImageHandler
}}{\void}
962 Destroys the wxImageHandler object.
964 \membersection{wxImageHandler::GetName
}
966 \constfunc{wxString
}{GetName
}{\void}
968 Gets the name of this handler.
970 \membersection{wxImageHandler::GetExtension
}
972 \constfunc{wxString
}{GetExtension
}{\void}
974 Gets the file extension associated with this handler.
976 \membersection{wxImageHandler::GetImageCount
}\label{wximagehandlergetimagecount
}
978 \func{int
}{GetImageCount
}{\param{wxInputStream\&
}{ stream
}}
980 If the image file contains more than one image and the image handler is capable
981 of retrieving these individually, this function will return the number of
984 \docparam{stream
}{Opened input stream for reading image data. Currently, the stream must support seeking.
}
986 \wxheading{Return value
}
988 Number of available images. For most image handlers, this is
1 (exceptions
989 are TIFF and ICO formats).
991 \membersection{wxImageHandler::GetType
}
993 \constfunc{long
}{GetType
}{\void}
995 Gets the image type associated with this handler.
997 \membersection{wxImageHandler::GetMimeType
}
999 \constfunc{wxString
}{GetMimeType
}{\void}
1001 Gets the MIME type associated with this handler.
1003 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
1005 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
},
\param{bool
}{ verbose=TRUE
},
\param{int
}{ index=
0}}
1007 Loads a image from a stream, putting the resulting data into
{\it image
}. If the image file contains
1008 more than one image and the image handler is capable of retrieving these individually,
{\it index
}
1009 indicates which image to read from the stream.
1011 \wxheading{Parameters
}
1013 \docparam{image
}{The image object which is to be affected by this operation.
}
1015 \docparam{stream
}{Opened input stream for reading image data.
}
1017 \docparam{verbose
}{If set to TRUE, errors reported by the image handler will produce wxLogMessages.
}
1019 \docparam{index
}{The index of the image in the file (starting from zero).
}
1021 \wxheading{Return value
}
1023 TRUE if the operation succeeded, FALSE otherwise.
1025 \wxheading{See also
}
1027 \helpref{wxImage::LoadFile
}{wximageloadfile
},
1028 \helpref{wxImage::SaveFile
}{wximagesavefile
},
1029 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
1031 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
1033 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
1035 Saves a image in the output stream.
1037 \wxheading{Parameters
}
1039 \docparam{image
}{The image object which is to be affected by this operation.
}
1041 \docparam{stream
}{Opened output stream for writing the data.
}
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::LoadFile
}{wximagehandlerloadfile
}
1053 \membersection{wxImageHandler::SetName
}
1055 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
1057 Sets the handler name.
1059 \wxheading{Parameters
}
1061 \docparam{name
}{Handler name.
}
1063 \membersection{wxImageHandler::SetExtension
}
1065 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
1067 Sets the handler extension.
1069 \wxheading{Parameters
}
1071 \docparam{extension
}{Handler extension.
}
1073 \membersection{wxImageHandler::SetMimeType
}\label{wximagehandlersetmimetype
}
1075 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
1077 Sets the handler MIME type.
1079 \wxheading{Parameters
}
1081 \docparam{mimename
}{Handler MIME type.
}
1083 \membersection{wxImageHandler::SetType
}
1085 \func{void
}{SetType
}{\param{long
}{type
}}
1087 Sets the handler type.
1089 \wxheading{Parameters
}
1091 \docparam{name
}{Handler type.
}