1 \section{\class{wxImage
}}\label{wximage
}
3 This class encapsulates a platform-independent image. An image can be created
4 from data, or using the constructor taking a wxBitmap object. An image
5 can be loaded from a file in a variety of formats, and is extensible to new formats
6 via image format handlers. Functions are available to set and get image bits, so
7 it can be used for basic image manipulation.
9 A wxImage cannot (currently) be drawn directly to a wxDC. Instead, a platform-specific
10 wxBitmap object must be created from it, and that bitmap drawn on the wxDC, using
13 \wxheading{Derived from
}
15 \helpref{wxObject
}{wxobject
}
17 \wxheading{Include files
}
23 \helpref{wxBitmap
}{wxbitmap
}
24 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
26 \latexignore{\rtfignore{\wxheading{Members
}}}
28 \membersection{wxImage::wxImage
}\label{wximageconstr
}
30 \func{}{wxImage
}{\void}
34 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
38 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
40 Constructs an image from a platform-dependent bitmap. This preserves
41 mask information so that bitmaps and images can be converted back
42 and forth without loss in that respect.
44 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
46 Creates an image with the given width and height.
48 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
50 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
52 Loads an image from a file.
54 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
56 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
58 Loads an image from an input stream.
60 \wxheading{Parameters
}
62 \docparam{width
}{Specifies the width of the image.
}
64 \docparam{height
}{Specifies the height of the image.
}
66 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
68 \docparam{stream
}{This refers to an input stream. Its meaning is determined by the
{\it type
} parameter. It is equal to loading from file except that you provide opened stream (file, HTTP or any other custom class).
}
70 \docparam{type
}{May be one of the following:
74 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
75 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
76 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_JPEG}}}{Load a JPEG bitmap file.
}
79 The validity of these flags depends on the platform and wxWindows configuration.
80 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
81 a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
84 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
86 Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
87 initialization in order to work with JPEGs.
91 \helpref{wxImage::LoadFile
}{wximageloadfile
}
93 \pythonnote{Constructors supported by wxPython are:
\par
94 \indented{2cm
}{\begin{twocollist
}
95 \twocolitem{\bf{wxImage(name, flag)
}}{Loads an image from a file
}
96 \twocolitem{\bf{wxNullImage()
}}{Create a null image (has no size or
98 \twocolitem{\bf{wxEmptyImage(width, height)
}}{Creates an empty image
100 \twocolitem{\bf{wxImageFromMime(name, mimetype
}}{Creates an image from
101 the given file of the given mimetype
}
102 \twocolitem{\bf{wxImageFromBitmap(bitmap)
}}{Creates an image from a
103 platform-dependent bitmap
}
107 \membersection{wxImage::
\destruct{wxImage
}}
109 \func{}{\destruct{wxImage
}}{\void}
113 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
115 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
117 Adds a handler to the end of the static list of format handlers.
119 \docparam{handler
}{A new image format handler object. There is usually only one instance
120 of a given handler class in an application session.
}
124 \helpref{wxImageHandler
}{wximagehandler
}
126 \pythonnote{In wxPython this static method is named
\tt{wxImage_AddHandler
}.
}
127 \membersection{wxImage::CleanUpHandlers
}
129 \func{static void
}{CleanUpHandlers
}{\void}
131 Deletes all image handlers.
133 This function is called by wxWindows on exit.
135 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
137 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
139 Converts the image to a platform-specific bitmap object. This has to be done
140 to actually display an image as you cannot draw an image directly on a window.
141 The resulting bitmap will use the colour depth of the current system which entails
142 that a (crude) colour reduction has to take place. When in
8-bit mode, this
143 routine will use a
color cube created on program start-up to look up colors.
144 Still, the image quality won't be perfect for photo images.
146 \membersection{wxImage::Create
}\label{wximagecreate
}
148 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
150 Creates a fresh image.
152 \wxheading{Parameters
}
154 \docparam{width
}{The width of the image in pixels.
}
156 \docparam{height
}{The height of the image in pixels.
}
158 \wxheading{Return value
}
160 TRUE if the call succeeded, FALSE otherwise.
162 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
164 \func{bool
}{Destroy
}{\void}
166 Destroys the image data.
168 \membersection{wxImage::FindHandler
}
170 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
172 Finds the handler with the given name.
174 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
176 Finds the handler associated with the given extension and type.
178 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
180 Finds the handler associated with the given image type.
182 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
184 Finds the handler associated with the given MIME type.
186 \docparam{name
}{The handler name.
}
188 \docparam{extension
}{The file extension, such as ``bmp".
}
190 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
192 \docparam{mimetype
}{MIME type.
}
194 \wxheading{Return value
}
196 A pointer to the handler if found, NULL otherwise.
200 \helpref{wxImageHandler
}{wximagehandler
}
202 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
204 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
206 Returns the blue intensity at the given coordinate.
208 \membersection{wxImage::GetData
}\label{wximagegetdata
}
210 \constfunc{unsigned char*
}{GetData
}{\void}
212 Returns the image data as an array. This is most often used when doing
213 direct image manipulation. The return value points to an array of
214 chararcters in RGBGBRGB... format.
216 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
218 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
220 Returns the green intensity at the given coordinate.
222 \membersection{wxImage::GetRed
}\label{wximagegetred
}
224 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
226 Returns the red intensity at the given coordinate.
228 \membersection{wxImage::GetHandlers
}
230 \func{static wxList\&
}{GetHandlers
}{\void}
232 Returns the static list of image format handlers.
236 \helpref{wxImageHandler
}{wximagehandler
}
238 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
240 \constfunc{int
}{GetHeight
}{\void}
242 Gets the height of the image in pixels.
244 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
246 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
248 Gets the blue value of the mask colour.
250 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
252 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
254 Gets the green value of the mask colour.
256 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
258 \constfunc{unsigned char
}{GetMaskRed
}{\void}
260 Gets the red value of the mask colour.
262 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
264 \constfunc{int
}{GetWidth
}{\void}
266 Gets the width of the image in pixels.
270 \helpref{wxImage::GetHeight
}{wximagegetheight
}
272 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
274 \constfunc{bool
}{HasMask
}{\void}
276 Returns TRUE if there is a mask active, FALSE otherwise.
278 \membersection{wxImage::InitStandardHandlers
}
280 \func{static void
}{InitStandardHandlers
}{\void}
282 Internal use only. Adds standard image format handlers. It only install BMP
283 for the time being, which is use by wxBitmap.
285 This function is called by wxWindows on startup, and shouldn't be called by
290 \helpref{wxImageHandler
}{wximagehandler
}
291 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
293 \membersection{wxImage::InsertHandler
}
295 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
297 Adds a handler at the start of the static list of format handlers.
299 \docparam{handler
}{A new image format handler object. There is usually only one instance
300 of a given handler class in an application session.
}
304 \helpref{wxImageHandler
}{wximagehandler
}
306 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
308 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY}}
310 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
}}
312 Loads an image from a file. If no handler type is provided, the library will
313 try to use wxBITMAP
\_TYPE\_BMP or all known handlers previously installed
314 through a call to
\helpref{wxImage::InitAllHandlers
}{wximageinitallhandlers
}.
316 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
318 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
}}
320 Loads an image from an input stream.
322 \wxheading{Parameters
}
324 \docparam{name
}{A filename.
325 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
327 \docparam{stream
}{An input stream.
328 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
330 \docparam{type
}{One of the following values:
334 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
335 \twocolitem{{\bf wxBITMAP
\_TYPE\_GIF}}{Load a GIF image file.
}
336 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
337 \twocolitem{{\bf wxBITMAP
\_TYPE\_PCX}}{Load a PCX image file.
}
338 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
339 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNM}}{Load a PNM image file.
}
342 The validity of these flags depends on the platform and wxWindows configuration.
}
344 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
346 \wxheading{Return value
}
348 TRUE if the operation succeeded, FALSE otherwise.
352 \helpref{wxImage::SaveFile
}{wximagesavefile
}
354 \pythonnote{In place of a single overloaded method name, wxPython
355 implements the following methods:
\par
356 \indented{2cm
}{\begin{twocollist
}
357 \twocolitem{\bf{LoadFile(filename, type)
}}{Loads an image of the given
359 \twocolitem{\bf{LoadMimeFile(filename, mimetype)
}}{Loads an image of the given
360 mimetype from a file
}
365 \membersection{wxImage::Ok
}\label{wximageok
}
367 \constfunc{bool
}{Ok
}{\void}
369 Returns TRUE if image data is present.
371 \membersection{wxImage::RemoveHandler
}
373 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
375 Finds the handler with the given name, and removes it. The handler
378 \docparam{name
}{The handler name.
}
380 \wxheading{Return value
}
382 TRUE if the handler was found and removed, FALSE otherwise.
386 \helpref{wxImageHandler
}{wximagehandler
}
388 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
390 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
392 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
394 Saves a image in the named file.
396 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
398 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
400 Saves a image in the given stream.
402 \wxheading{Parameters
}
404 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
406 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
408 \docparam{type
}{Currently two types can be used:
412 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
413 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
416 The validity of these flags depends on the platform and wxWindows configuration
417 as well as user-added handlers.
}
419 \docparam{mimetype
}{MIME type.
}
421 \wxheading{Return value
}
423 TRUE if the operation succeeded, FALSE otherwise.
427 Depending on how wxWindows has been configured, not all formats may be available.
431 \helpref{wxImage::LoadFile
}{wximageloadfile
}
433 \pythonnote{In place of a single overloaded method name, wxPython
434 implements the following methods:
\par
435 \indented{2cm
}{\begin{twocollist
}
436 \twocolitem{\bf{SaveFile(filename, type)
}}{Saves the image using the given
437 type to the named file
}
438 \twocolitem{\bf{SaveMimeFile(filename, mimetype)
}}{Saves the image using the given
439 mimetype to the named file
}
443 \membersection{wxImage::Rescale
}\label{wximagerescale
}
445 \func{wxImage
}{Rescale
}{\param{int
}{ width
},
\param{int
}{ height
}}
447 Changes the size of the image in-place: after a call to this function, the
448 image will have the given width and height.
452 \helpref{Scale
}{wximagescale
}
454 \membersection{wxImage::Scale
}\label{wximagescale
}
456 \constfunc{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
458 Returns a scaled version of the image. This is also useful for
459 scaling bitmaps in general as the only other way to scale bitmaps
460 is to blit a wxMemoryDC into another wxMemoryDC.
462 NB: although Windows can do such scaling itself but in the GTK port, scaling
463 bitmaps is done using this routine internally.
468 // get the bitmap from somewhere
471 // rescale it to have size of
32*
32
472 if ( bmp.GetWidth() !=
32 || bmp.GetHeight() !=
32 )
475 bmp = image.Scale(
32,
32).ConvertToBitmap();
477 // another possibility:
478 image.Rescale(
32,
32);
486 \helpref{Rescale
}{wximagerescale
}
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::SetData
}\label{wximagesetdata
}
497 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
499 Sets the image data without performing checks. The data given must have
500 the size (width*height*
3) or results will be unexpected. Don't use this
501 method if you aren't sure you know what you are doing.
503 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
505 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
507 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
509 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
511 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
513 Sets the mask colour for this image (and tells the image to use the mask).
515 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
517 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
519 Sets the pixel at the given coordinate. This routine performs bounds-checks
520 for the coordinate so it can be considered a safe way to manipulate the
521 data, but in some cases this might be too slow so that the data will have to
522 be set directly. In that case you have to get that data by calling GetData().
524 \membersection{wxImage::operator $=$
}
526 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
528 Assignment operator. This operator does not copy any data, but instead
529 passes a pointer to the data in
{\it image
} and increments a reference
530 counter. It is a fast operation.
532 \wxheading{Parameters
}
534 \docparam{image
}{Image to assign.
}
536 \wxheading{Return value
}
538 Returns 'this' object.
540 \membersection{wxImage::operator $==$
}
542 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
544 Equality operator. This operator tests whether the internal data pointers are
547 \wxheading{Parameters
}
549 \docparam{image
}{Image to compare with 'this'
}
551 \wxheading{Return value
}
553 Returns TRUE if the images were effectively equal, FALSE otherwise.
555 \membersection{wxImage::operator $!=$
}
557 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
559 Inequality operator. This operator tests whether the internal data pointers are
560 unequal (a fast test).
562 \wxheading{Parameters
}
564 \docparam{image
}{Image to compare with 'this'
}
566 \wxheading{Return value
}
568 Returns TRUE if the images were unequal, FALSE otherwise.
570 \section{\class{wxImageHandler
}}\label{wximagehandler
}
572 This is the base class for implementing image file loading/saving, and image creation from data.
573 It is used within wxImage and is not normally seen by the application.
575 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
576 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
577 application initialisation.
579 \wxheading{Note (Legal Issue)
}
581 This software is based in part on the work of the Independent JPEG Group.
583 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
586 \wxheading{Derived from
}
588 \helpref{wxObject
}{wxobject
}
590 \wxheading{Include files
}
596 \helpref{wxImage
}{wximage
}
597 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
599 \latexignore{\rtfignore{\wxheading{Members
}}}
601 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
603 \func{}{wxImageHandler
}{\void}
605 Default constructor. In your own default constructor, initialise the members
606 m
\_name, m
\_extension and m
\_type.
608 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
610 \func{}{\destruct{wxImageHandler
}}{\void}
612 Destroys the wxImageHandler object.
614 \membersection{wxImageHandler::GetName
}
616 \constfunc{wxString
}{GetName
}{\void}
618 Gets the name of this handler.
620 \membersection{wxImageHandler::GetExtension
}
622 \constfunc{wxString
}{GetExtension
}{\void}
624 Gets the file extension associated with this handler.
626 \membersection{wxImageHandler::GetType
}
628 \constfunc{long
}{GetType
}{\void}
630 Gets the image type associated with this handler.
632 \membersection{wxImageHandler::GetMimeType
}
634 \constfunc{wxString
}{GetMimeType
}{\void}
636 Gets the MIME type associated with this handler.
638 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
640 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
642 Loads a image from a stream, putting the resulting data into
{\it image
}.
644 \wxheading{Parameters
}
646 \docparam{image
}{The image object which is to be affected by this operation.
}
648 \docparam{stream
}{Opened input stream.
649 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
651 \wxheading{Return value
}
653 TRUE if the operation succeeded, FALSE otherwise.
657 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
658 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
659 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
661 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
663 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
665 Saves a image in the output stream.
667 \wxheading{Parameters
}
669 \docparam{image
}{The image object which is to be affected by this operation.
}
671 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
673 \wxheading{Return value
}
675 TRUE if the operation succeeded, FALSE otherwise.
679 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
680 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
681 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
683 \membersection{wxImageHandler::SetName
}
685 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
687 Sets the handler name.
689 \wxheading{Parameters
}
691 \docparam{name
}{Handler name.
}
693 \membersection{wxImageHandler::SetExtension
}
695 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
697 Sets the handler extension.
699 \wxheading{Parameters
}
701 \docparam{extension
}{Handler extension.
}
703 \membersection{wxImageHandler::SetType
}
705 \func{void
}{SetType
}{\param{long
}{type
}}
707 Sets the handler type.
709 \wxheading{Parameters
}
711 \docparam{name
}{Handler type.
}
714 \membersection{wxImageHandler::SetMimeType
}
716 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
718 Sets the handler MIME type.
720 \wxheading{Parameters
}
722 \docparam{mimename
}{Handler MIME type.
}