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
}
19 \helpref{wxBitmap
}{wxbitmap
}
21 \latexignore{\rtfignore{\wxheading{Members
}}}
23 \membersection{wxImage::wxImage
}\label{wximageconstr
}
25 \func{}{wxImage
}{\void}
29 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
33 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
35 Constructs an image from a platform-dependent bitmap. This preserves
36 mask information so that bitmaps and images can be converted back
37 and forth without loss in that respect.
39 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
}}
41 Creates an image with the given width and height.
43 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
45 Loads an image from a file.
47 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
49 Loads an image from an input stream.
51 \wxheading{Parameters
}
53 \docparam{width
}{Specifies the width of the image.
}
55 \docparam{height
}{Specifies the height of the image.
}
57 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
59 \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).
}
61 \docparam{type
}{May be one of the following:
65 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
66 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
67 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_JPEG}}}{Load a JPEG bitmap file.
}
70 The validity of these flags depends on the platform and wxWindows configuration.
71 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
72 a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
77 \helpref{wxImage::LoadFile
}{wximageloadfile
}
79 \membersection{wxImage::
\destruct{wxImage
}}
81 \func{}{\destruct{wxImage
}}{\void}
85 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
87 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
89 Adds a handler to the end of the static list of format handlers.
91 \docparam{handler
}{A new image format handler object. There is usually only one instance
92 of a given handler class in an application session.
}
96 \helpref{wxImageHandler
}{wximagehandler
}
98 \membersection{wxImage::CleanUpHandlers
}
100 \func{static void
}{CleanUpHandlers
}{\void}
102 Deletes all image handlers.
104 This function is called by wxWindows on exit.
106 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
108 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
110 Converts the image to a platform-specific bitmap object. This has to be done
111 to actually display an image as you cannot draw an image directly on a window.
112 The resulting bitmap will use the colour depth of the current system which entails
113 that a (crude) colour reduction has to take place. When in
8-bit mode, this
114 routine will use a
color cube created on program start-up to look up colors.
115 Still, the image quality won't be perfect for photo images.
117 \membersection{wxImage::Create
}\label{wximagecreate
}
119 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
121 Creates a fresh image.
123 \wxheading{Parameters
}
125 \docparam{width
}{The width of the image in pixels.
}
127 \docparam{height
}{The height of the image in pixels.
}
129 \wxheading{Return value
}
131 TRUE if the call succeeded, FALSE otherwise.
133 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
135 \func{bool
}{Destroy
}{\void}
137 Destroys the image data.
139 \membersection{wxImage::FindHandler
}
141 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
143 Finds the handler with the given name.
145 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
147 Finds the handler associated with the given extension and type.
149 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
151 Finds the handler associated with the given image type.
153 \docparam{name
}{The handler name.
}
155 \docparam{extension
}{The file extension, such as ``bmp".
}
157 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
159 \wxheading{Return value
}
161 A pointer to the handler if found, NULL otherwise.
165 \helpref{wxImageHandler
}{wximagehandler
}
167 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
169 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
171 Returns the blue intensity at the given coordinate.
173 \membersection{wxImage::GetData
}\label{wximagegetdata
}
175 \constfunc{unsigned char*
}{GetData
}{\void}
177 Returns the image data as an array. This is most often used when doing
178 direct image manipulation. The return value points to an array of
179 chararcters in RGBGBRGB... format.
181 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
183 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
185 Returns the green intensity at the given coordinate.
187 \membersection{wxImage::GetRed
}\label{wximagegetred
}
189 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
191 Returns the red intensity at the given coordinate.
193 \membersection{wxImage::GetHandlers
}
195 \func{static wxList\&
}{GetHandlers
}{\void}
197 Returns the static list of image format handlers.
201 \helpref{wxImageHandler
}{wximagehandler
}
203 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
205 \constfunc{int
}{GetHeight
}{\void}
207 Gets the height of the image in pixels.
209 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
211 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
213 Gets the blue value of the mask colour.
215 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
217 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
219 Gets the green value of the mask colour.
221 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
223 \constfunc{unsigned char
}{GetMaskRed
}{\void}
225 Gets the red value of the mask colour.
227 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
229 \constfunc{int
}{GetWidth
}{\void}
231 Gets the width of the image in pixels.
235 \helpref{wxImage::GetHeight
}{wximagegetheight
}
237 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
239 \constfunc{bool
}{HasMask
}{\void}
241 Returns TRUE if there is a mask active, FALSE otherwise.
243 \membersection{wxImage::InitStandardHandlers
}
245 \func{static void
}{InitStandardHandlers
}{\void}
247 Adds the standard image format handlers, which, depending on wxWindows
248 configuration, can be handlers for Windows BMP (loading), PNG
249 (loading and saving) and JPEG (loading and saving) file formats.
251 This function is called by wxWindows on startup.
255 \helpref{wxImageHandler
}{wximagehandler
}
257 \membersection{wxImage::InsertHandler
}
259 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
261 Adds a handler at the start of the static list of format handlers.
263 \docparam{handler
}{A new image format handler object. There is usually only one instance
264 of a given handler class in an application session.
}
268 \helpref{wxImageHandler
}{wximagehandler
}
270 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
272 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
274 Loads an image from a file.
276 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
278 Loads an image from an input stream.
280 \wxheading{Parameters
}
282 \docparam{name
}{A filename.
283 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
285 \docparam{stream
}{An input stream.
286 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
288 \docparam{type
}{One of the following values:
292 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
293 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
294 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
297 The validity of these flags depends on the platform and wxWindows configuration.
}
299 \wxheading{Return value
}
301 TRUE if the operation succeeded, FALSE otherwise.
305 \helpref{wxImage::SaveFile
}{wximagesavefile
}
307 \membersection{wxImage::Ok
}\label{wximageok
}
309 \constfunc{bool
}{Ok
}{\void}
311 Returns TRUE if image data is present.
313 \membersection{wxImage::RemoveHandler
}
315 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
317 Finds the handler with the given name, and removes it. The handler
320 \docparam{name
}{The handler name.
}
322 \wxheading{Return value
}
324 TRUE if the handler was found and removed, FALSE otherwise.
328 \helpref{wxImageHandler
}{wximagehandler
}
330 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
332 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
334 Saves a image in the named file.
336 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
338 Saves a image in the given stream.
340 \wxheading{Parameters
}
342 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
344 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
346 \docparam{type
}{Currently two types can be used:
350 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
351 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
354 The validity of these flags depends on the platform and wxWindows configuration
355 as well as user-added handlers.
}
357 \wxheading{Return value
}
359 TRUE if the operation succeeded, FALSE otherwise.
363 Depending on how wxWindows has been configured, not all formats may be available.
367 \helpref{wxImage::LoadFile
}{wximageloadfile
}
369 \membersection{wxImage::Scale
}\label{wximagescale
}
371 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
373 Returns a scaled version of the image. This is also useful for
374 scaling bitmaps in general as the only other way to scale bitmaps
375 is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such
376 scaling itself but in the GTK port, scaling bitmaps is done using
377 this routine internally.
379 \membersection{wxImage::SetData
}\label{wximagesetdata
}
381 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
383 Sets the image data without performing checks. The data given must have
384 the size (width*height*
3) or results will be unexpected. Don't use this
385 method if you aren't sure you know what you are doing.
387 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
389 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
391 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
393 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
395 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
397 Sets the mask colour for this image (and tells the image to use the mask).
399 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
401 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
403 Sets the pixel at the given coordinate. This routine performs bounds-checks
404 for the coordinate so it can be considered a safe way to manipulate the
405 data, but in some cases this might be too slow so that the data will have to
406 be set directly. In that case you have to get that data by calling GetData().
408 \membersection{wxImage::operator $=$
}
410 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
412 Assignment operator. This operator does not copy any data, but instead
413 passes a pointer to the data in
{\it image
} and increments a reference
414 counter. It is a fast operation.
416 \wxheading{Parameters
}
418 \docparam{image
}{Image to assign.
}
420 \wxheading{Return value
}
422 Returns 'this' object.
424 \membersection{wxImage::operator $==$
}
426 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
428 Equality operator. This operator tests whether the internal data pointers are
431 \wxheading{Parameters
}
433 \docparam{image
}{Image to compare with 'this'
}
435 \wxheading{Return value
}
437 Returns TRUE if the images were effectively equal, FALSE otherwise.
439 \membersection{wxImage::operator $!=$
}
441 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
443 Inequality operator. This operator tests whether the internal data pointers are
444 unequal (a fast test).
446 \wxheading{Parameters
}
448 \docparam{image
}{Image to compare with 'this'
}
450 \wxheading{Return value
}
452 Returns TRUE if the images were unequal, FALSE otherwise.
454 \section{\class{wxImageHandler
}}\label{wximagehandler
}
456 This is the base class for implementing image file loading/saving, and image creation from data.
457 It is used within wxImage and is not normally seen by the application.
459 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
460 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
461 application initialisation.
463 \wxheading{Note (Legal Issue)
}
465 This software is based in part on the work of
466 the Independent JPEG Group.
468 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
471 \wxheading{Derived from
}
473 \helpref{wxObject
}{wxobject
}
477 \helpref{wxImage
}{wximage
}
479 \latexignore{\rtfignore{\wxheading{Members
}}}
481 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
483 \func{}{wxImageHandler
}{\void}
485 Default constructor. In your own default constructor, initialise the members
486 m
\_name, m
\_extension and m
\_type.
488 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
490 \func{}{\destruct{wxImageHandler
}}{\void}
492 Destroys the wxImageHandler object.
494 \membersection{wxImageHandler::GetName
}
496 \constfunc{wxString
}{GetName
}{\void}
498 Gets the name of this handler.
500 \membersection{wxImageHandler::GetExtension
}
502 \constfunc{wxString
}{GetExtension
}{\void}
504 Gets the file extension associated with this handler.
506 \membersection{wxImageHandler::GetType
}
508 \constfunc{long
}{GetType
}{\void}
510 Gets the image type associated with this handler.
512 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
514 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
516 Loads a image from a stream, putting the resulting data into
{\it image
}.
518 \wxheading{Parameters
}
520 \docparam{image
}{The image object which is to be affected by this operation.
}
522 \docparam{stream
}{Opened input stream.
523 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
525 \wxheading{Return value
}
527 TRUE if the operation succeeded, FALSE otherwise.
531 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
532 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
533 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
535 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
537 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
539 Saves a image in the output stream.
541 \wxheading{Parameters
}
543 \docparam{image
}{The image object which is to be affected by this operation.
}
545 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
547 \wxheading{Return value
}
549 TRUE if the operation succeeded, FALSE otherwise.
553 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
554 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
555 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
557 \membersection{wxImageHandler::SetName
}
559 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
561 Sets the handler name.
563 \wxheading{Parameters
}
565 \docparam{name
}{Handler name.
}
567 \membersection{wxImageHandler::SetExtension
}
569 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
571 Sets the handler extension.
573 \wxheading{Parameters
}
575 \docparam{extension
}{Handler extension.
}
577 \membersection{wxImageHandler::SetType
}
579 \func{void
}{SetType
}{\param{long
}{type
}}
581 Sets the handler type.
583 \wxheading{Parameters
}
585 \docparam{name
}{Handler type.
}