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
}
25 \latexignore{\rtfignore{\wxheading{Members
}}}
27 \membersection{wxImage::wxImage
}\label{wximageconstr
}
29 \func{}{wxImage
}{\void}
33 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
37 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
39 Constructs an image from a platform-dependent bitmap. This preserves
40 mask information so that bitmaps and images can be converted back
41 and forth without loss in that respect.
43 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
45 Creates an image with the given width and height.
47 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
49 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
51 Loads an image from a file.
53 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
55 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
57 Loads an image from an input stream.
59 \wxheading{Parameters
}
61 \docparam{width
}{Specifies the width of the image.
}
63 \docparam{height
}{Specifies the height of the image.
}
65 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
67 \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).
}
69 \docparam{type
}{May be one of the following:
73 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
74 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
75 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_JPEG}}}{Load a JPEG bitmap file.
}
78 The validity of these flags depends on the platform and wxWindows configuration.
79 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
80 a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
83 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
85 Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
86 initialization in order to work with JPEGs.
90 \helpref{wxImage::LoadFile
}{wximageloadfile
}
92 \membersection{wxImage::
\destruct{wxImage
}}
94 \func{}{\destruct{wxImage
}}{\void}
98 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
100 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
102 Adds a handler to the end of the static list of format handlers.
104 \docparam{handler
}{A new image format handler object. There is usually only one instance
105 of a given handler class in an application session.
}
109 \helpref{wxImageHandler
}{wximagehandler
}
111 \membersection{wxImage::CleanUpHandlers
}
113 \func{static void
}{CleanUpHandlers
}{\void}
115 Deletes all image handlers.
117 This function is called by wxWindows on exit.
119 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
121 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
123 Converts the image to a platform-specific bitmap object. This has to be done
124 to actually display an image as you cannot draw an image directly on a window.
125 The resulting bitmap will use the colour depth of the current system which entails
126 that a (crude) colour reduction has to take place. When in
8-bit mode, this
127 routine will use a
color cube created on program start-up to look up colors.
128 Still, the image quality won't be perfect for photo images.
130 \membersection{wxImage::Create
}\label{wximagecreate
}
132 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
134 Creates a fresh image.
136 \wxheading{Parameters
}
138 \docparam{width
}{The width of the image in pixels.
}
140 \docparam{height
}{The height of the image in pixels.
}
142 \wxheading{Return value
}
144 TRUE if the call succeeded, FALSE otherwise.
146 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
148 \func{bool
}{Destroy
}{\void}
150 Destroys the image data.
152 \membersection{wxImage::FindHandler
}
154 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
156 Finds the handler with the given name.
158 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
160 Finds the handler associated with the given extension and type.
162 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
164 Finds the handler associated with the given image type.
166 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
168 Finds the handler associated with the given MIME type.
170 \docparam{name
}{The handler name.
}
172 \docparam{extension
}{The file extension, such as ``bmp".
}
174 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
176 \docparam{mimetype
}{MIME type.
}
178 \wxheading{Return value
}
180 A pointer to the handler if found, NULL otherwise.
184 \helpref{wxImageHandler
}{wximagehandler
}
186 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
188 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
190 Returns the blue intensity at the given coordinate.
192 \membersection{wxImage::GetData
}\label{wximagegetdata
}
194 \constfunc{unsigned char*
}{GetData
}{\void}
196 Returns the image data as an array. This is most often used when doing
197 direct image manipulation. The return value points to an array of
198 chararcters in RGBGBRGB... format.
200 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
202 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
204 Returns the green intensity at the given coordinate.
206 \membersection{wxImage::GetRed
}\label{wximagegetred
}
208 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
210 Returns the red intensity at the given coordinate.
212 \membersection{wxImage::GetHandlers
}
214 \func{static wxList\&
}{GetHandlers
}{\void}
216 Returns the static list of image format handlers.
220 \helpref{wxImageHandler
}{wximagehandler
}
222 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
224 \constfunc{int
}{GetHeight
}{\void}
226 Gets the height of the image in pixels.
228 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
230 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
232 Gets the blue value of the mask colour.
234 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
236 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
238 Gets the green value of the mask colour.
240 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
242 \constfunc{unsigned char
}{GetMaskRed
}{\void}
244 Gets the red value of the mask colour.
246 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
248 \constfunc{int
}{GetWidth
}{\void}
250 Gets the width of the image in pixels.
254 \helpref{wxImage::GetHeight
}{wximagegetheight
}
256 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
258 \constfunc{bool
}{HasMask
}{\void}
260 Returns TRUE if there is a mask active, FALSE otherwise.
262 \membersection{wxImage::InitStandardHandlers
}
264 \func{static void
}{InitStandardHandlers
}{\void}
266 Adds the standard image format handlers, which, depending on wxWindows
267 configuration, can be handlers for Windows BMP (loading), PNG
268 (loading and saving) and JPEG (loading and saving) file formats.
270 This function is called by wxWindows on startup.
274 \helpref{wxImageHandler
}{wximagehandler
}
276 \membersection{wxImage::InsertHandler
}
278 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
280 Adds a handler at the start of the static list of format handlers.
282 \docparam{handler
}{A new image format handler object. There is usually only one instance
283 of a given handler class in an application session.
}
287 \helpref{wxImageHandler
}{wximagehandler
}
289 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
291 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
293 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{const wxString\&
}{ mimetype
}}
295 Loads an image from a file.
297 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
299 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{const wxString\&
}{ mimetype
}}
301 Loads an image from an input stream.
303 \wxheading{Parameters
}
305 \docparam{name
}{A filename.
306 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
308 \docparam{stream
}{An input stream.
309 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
311 \docparam{type
}{One of the following values:
315 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
316 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
317 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
320 The validity of these flags depends on the platform and wxWindows configuration.
}
322 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
324 \wxheading{Return value
}
326 TRUE if the operation succeeded, FALSE otherwise.
330 \helpref{wxImage::SaveFile
}{wximagesavefile
}
332 \membersection{wxImage::Ok
}\label{wximageok
}
334 \constfunc{bool
}{Ok
}{\void}
336 Returns TRUE if image data is present.
338 \membersection{wxImage::RemoveHandler
}
340 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
342 Finds the handler with the given name, and removes it. The handler
345 \docparam{name
}{The handler name.
}
347 \wxheading{Return value
}
349 TRUE if the handler was found and removed, FALSE otherwise.
353 \helpref{wxImageHandler
}{wximagehandler
}
355 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
357 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
359 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
}}
361 Saves a image in the named file.
363 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
365 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
}}
367 Saves a image in the given stream.
369 \wxheading{Parameters
}
371 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
373 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
375 \docparam{type
}{Currently two types can be used:
379 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
380 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
383 The validity of these flags depends on the platform and wxWindows configuration
384 as well as user-added handlers.
}
386 \docparam{mimetype
}{MIME type.
}
388 \wxheading{Return value
}
390 TRUE if the operation succeeded, FALSE otherwise.
394 Depending on how wxWindows has been configured, not all formats may be available.
398 \helpref{wxImage::LoadFile
}{wximageloadfile
}
400 \membersection{wxImage::Scale
}\label{wximagescale
}
402 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
404 Returns a scaled version of the image. This is also useful for
405 scaling bitmaps in general as the only other way to scale bitmaps
406 is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such
407 scaling itself but in the GTK port, scaling bitmaps is done using
408 this routine internally.
410 \membersection{wxImage::SetData
}\label{wximagesetdata
}
412 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
414 Sets the image data without performing checks. The data given must have
415 the size (width*height*
3) or results will be unexpected. Don't use this
416 method if you aren't sure you know what you are doing.
418 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
420 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
422 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
424 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
426 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
428 Sets the mask colour for this image (and tells the image to use the mask).
430 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
432 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
434 Sets the pixel at the given coordinate. This routine performs bounds-checks
435 for the coordinate so it can be considered a safe way to manipulate the
436 data, but in some cases this might be too slow so that the data will have to
437 be set directly. In that case you have to get that data by calling GetData().
439 \membersection{wxImage::operator $=$
}
441 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
443 Assignment operator. This operator does not copy any data, but instead
444 passes a pointer to the data in
{\it image
} and increments a reference
445 counter. It is a fast operation.
447 \wxheading{Parameters
}
449 \docparam{image
}{Image to assign.
}
451 \wxheading{Return value
}
453 Returns 'this' object.
455 \membersection{wxImage::operator $==$
}
457 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
459 Equality operator. This operator tests whether the internal data pointers are
462 \wxheading{Parameters
}
464 \docparam{image
}{Image to compare with 'this'
}
466 \wxheading{Return value
}
468 Returns TRUE if the images were effectively equal, FALSE otherwise.
470 \membersection{wxImage::operator $!=$
}
472 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
474 Inequality operator. This operator tests whether the internal data pointers are
475 unequal (a fast test).
477 \wxheading{Parameters
}
479 \docparam{image
}{Image to compare with 'this'
}
481 \wxheading{Return value
}
483 Returns TRUE if the images were unequal, FALSE otherwise.
485 \section{\class{wxImageHandler
}}\label{wximagehandler
}
487 This is the base class for implementing image file loading/saving, and image creation from data.
488 It is used within wxImage and is not normally seen by the application.
490 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
491 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
492 application initialisation.
494 \wxheading{Note (Legal Issue)
}
496 This software is based in part on the work of the Independent JPEG Group.
498 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
501 \wxheading{Derived from
}
503 \helpref{wxObject
}{wxobject
}
505 \wxheading{Include files
}
511 \helpref{wxImage
}{wximage
}
513 \latexignore{\rtfignore{\wxheading{Members
}}}
515 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
517 \func{}{wxImageHandler
}{\void}
519 Default constructor. In your own default constructor, initialise the members
520 m
\_name, m
\_extension and m
\_type.
522 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
524 \func{}{\destruct{wxImageHandler
}}{\void}
526 Destroys the wxImageHandler object.
528 \membersection{wxImageHandler::GetName
}
530 \constfunc{wxString
}{GetName
}{\void}
532 Gets the name of this handler.
534 \membersection{wxImageHandler::GetExtension
}
536 \constfunc{wxString
}{GetExtension
}{\void}
538 Gets the file extension associated with this handler.
540 \membersection{wxImageHandler::GetType
}
542 \constfunc{long
}{GetType
}{\void}
544 Gets the image type associated with this handler.
546 \membersection{wxImageHandler::GetMimeType
}
548 \constfunc{wxString
}{GetMimeType
}{\void}
550 Gets the MIME type associated with this handler.
552 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
554 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
556 Loads a image from a stream, putting the resulting data into
{\it image
}.
558 \wxheading{Parameters
}
560 \docparam{image
}{The image object which is to be affected by this operation.
}
562 \docparam{stream
}{Opened input stream.
563 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
565 \wxheading{Return value
}
567 TRUE if the operation succeeded, FALSE otherwise.
571 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
572 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
573 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
575 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
577 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
579 Saves a image in the output stream.
581 \wxheading{Parameters
}
583 \docparam{image
}{The image object which is to be affected by this operation.
}
585 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
587 \wxheading{Return value
}
589 TRUE if the operation succeeded, FALSE otherwise.
593 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
594 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
595 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
597 \membersection{wxImageHandler::SetName
}
599 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
601 Sets the handler name.
603 \wxheading{Parameters
}
605 \docparam{name
}{Handler name.
}
607 \membersection{wxImageHandler::SetExtension
}
609 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
611 Sets the handler extension.
613 \wxheading{Parameters
}
615 \docparam{extension
}{Handler extension.
}
617 \membersection{wxImageHandler::SetType
}
619 \func{void
}{SetType
}{\param{long
}{type
}}
621 Sets the handler type.
623 \wxheading{Parameters
}
625 \docparam{name
}{Handler type.
}
628 \membersection{wxImageHandler::SetMimeType
}
630 \func{void
}{SetMimeType
}{\param{const wxString\&
}{mimetype
}}
632 Sets the handler MIME type.
634 \wxheading{Parameters
}
636 \docparam{mimename
}{Handler MIME type.
}