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 Loads an image from a file.
51 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_PNG}}
53 Loads an image from an input stream.
55 \wxheading{Parameters
}
57 \docparam{width
}{Specifies the width of the image.
}
59 \docparam{height
}{Specifies the height of the image.
}
61 \docparam{name
}{This refers to an image filename. Its meaning is determined by the
{\it type
} parameter.
}
63 \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).
}
65 \docparam{type
}{May be one of the following:
69 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_BMP}}}{Load a Windows bitmap file.
}
70 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_PNG}}}{Load a PNG bitmap file.
}
71 \twocolitem{{\bf \indexit{wxBITMAP
\_TYPE\_JPEG}}}{Load a JPEG bitmap file.
}
74 The validity of these flags depends on the platform and wxWindows configuration.
75 If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
76 a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
79 Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
80 initialization in order to work with JPEGs.
84 \helpref{wxImage::LoadFile
}{wximageloadfile
}
86 \membersection{wxImage::
\destruct{wxImage
}}
88 \func{}{\destruct{wxImage
}}{\void}
92 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
94 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
96 Adds a handler to the end of the static list of format handlers.
98 \docparam{handler
}{A new image format handler object. There is usually only one instance
99 of a given handler class in an application session.
}
103 \helpref{wxImageHandler
}{wximagehandler
}
105 \membersection{wxImage::CleanUpHandlers
}
107 \func{static void
}{CleanUpHandlers
}{\void}
109 Deletes all image handlers.
111 This function is called by wxWindows on exit.
113 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
115 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
117 Converts the image to a platform-specific bitmap object. This has to be done
118 to actually display an image as you cannot draw an image directly on a window.
119 The resulting bitmap will use the colour depth of the current system which entails
120 that a (crude) colour reduction has to take place. When in
8-bit mode, this
121 routine will use a
color cube created on program start-up to look up colors.
122 Still, the image quality won't be perfect for photo images.
124 \membersection{wxImage::Create
}\label{wximagecreate
}
126 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
128 Creates a fresh image.
130 \wxheading{Parameters
}
132 \docparam{width
}{The width of the image in pixels.
}
134 \docparam{height
}{The height of the image in pixels.
}
136 \wxheading{Return value
}
138 TRUE if the call succeeded, FALSE otherwise.
140 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
142 \func{bool
}{Destroy
}{\void}
144 Destroys the image data.
146 \membersection{wxImage::FindHandler
}
148 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
150 Finds the handler with the given name.
152 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
154 Finds the handler associated with the given extension and type.
156 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
158 Finds the handler associated with the given image type.
160 \docparam{name
}{The handler name.
}
162 \docparam{extension
}{The file extension, such as ``bmp".
}
164 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
166 \wxheading{Return value
}
168 A pointer to the handler if found, NULL otherwise.
172 \helpref{wxImageHandler
}{wximagehandler
}
174 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
176 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
178 Returns the blue intensity at the given coordinate.
180 \membersection{wxImage::GetData
}\label{wximagegetdata
}
182 \constfunc{unsigned char*
}{GetData
}{\void}
184 Returns the image data as an array. This is most often used when doing
185 direct image manipulation. The return value points to an array of
186 chararcters in RGBGBRGB... format.
188 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
190 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
192 Returns the green intensity at the given coordinate.
194 \membersection{wxImage::GetRed
}\label{wximagegetred
}
196 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
198 Returns the red intensity at the given coordinate.
200 \membersection{wxImage::GetHandlers
}
202 \func{static wxList\&
}{GetHandlers
}{\void}
204 Returns the static list of image format handlers.
208 \helpref{wxImageHandler
}{wximagehandler
}
210 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
212 \constfunc{int
}{GetHeight
}{\void}
214 Gets the height of the image in pixels.
216 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
218 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
220 Gets the blue value of the mask colour.
222 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
224 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
226 Gets the green value of the mask colour.
228 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
230 \constfunc{unsigned char
}{GetMaskRed
}{\void}
232 Gets the red value of the mask colour.
234 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
236 \constfunc{int
}{GetWidth
}{\void}
238 Gets the width of the image in pixels.
242 \helpref{wxImage::GetHeight
}{wximagegetheight
}
244 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
246 \constfunc{bool
}{HasMask
}{\void}
248 Returns TRUE if there is a mask active, FALSE otherwise.
250 \membersection{wxImage::InitStandardHandlers
}
252 \func{static void
}{InitStandardHandlers
}{\void}
254 Adds the standard image format handlers, which, depending on wxWindows
255 configuration, can be handlers for Windows BMP (loading), PNG
256 (loading and saving) and JPEG (loading and saving) file formats.
258 This function is called by wxWindows on startup.
262 \helpref{wxImageHandler
}{wximagehandler
}
264 \membersection{wxImage::InsertHandler
}
266 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
268 Adds a handler at the start of the static list of format handlers.
270 \docparam{handler
}{A new image format handler object. There is usually only one instance
271 of a given handler class in an application session.
}
275 \helpref{wxImageHandler
}{wximagehandler
}
277 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
279 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
281 Loads an image from a file.
283 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
285 Loads an image from an input stream.
287 \wxheading{Parameters
}
289 \docparam{name
}{A filename.
290 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
292 \docparam{stream
}{An input stream.
293 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
295 \docparam{type
}{One of the following values:
299 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
300 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
301 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
304 The validity of these flags depends on the platform and wxWindows configuration.
}
306 \wxheading{Return value
}
308 TRUE if the operation succeeded, FALSE otherwise.
312 \helpref{wxImage::SaveFile
}{wximagesavefile
}
314 \membersection{wxImage::Ok
}\label{wximageok
}
316 \constfunc{bool
}{Ok
}{\void}
318 Returns TRUE if image data is present.
320 \membersection{wxImage::RemoveHandler
}
322 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
324 Finds the handler with the given name, and removes it. The handler
327 \docparam{name
}{The handler name.
}
329 \wxheading{Return value
}
331 TRUE if the handler was found and removed, FALSE otherwise.
335 \helpref{wxImageHandler
}{wximagehandler
}
337 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
339 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
341 Saves a image in the named file.
343 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
345 Saves a image in the given stream.
347 \wxheading{Parameters
}
349 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
351 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
353 \docparam{type
}{Currently two types can be used:
357 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
358 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
361 The validity of these flags depends on the platform and wxWindows configuration
362 as well as user-added handlers.
}
364 \wxheading{Return value
}
366 TRUE if the operation succeeded, FALSE otherwise.
370 Depending on how wxWindows has been configured, not all formats may be available.
374 \helpref{wxImage::LoadFile
}{wximageloadfile
}
376 \membersection{wxImage::Scale
}\label{wximagescale
}
378 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
380 Returns a scaled version of the image. This is also useful for
381 scaling bitmaps in general as the only other way to scale bitmaps
382 is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such
383 scaling itself but in the GTK port, scaling bitmaps is done using
384 this routine internally.
386 \membersection{wxImage::SetData
}\label{wximagesetdata
}
388 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
390 Sets the image data without performing checks. The data given must have
391 the size (width*height*
3) or results will be unexpected. Don't use this
392 method if you aren't sure you know what you are doing.
394 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
396 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
398 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
400 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
402 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
404 Sets the mask colour for this image (and tells the image to use the mask).
406 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
408 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
410 Sets the pixel at the given coordinate. This routine performs bounds-checks
411 for the coordinate so it can be considered a safe way to manipulate the
412 data, but in some cases this might be too slow so that the data will have to
413 be set directly. In that case you have to get that data by calling GetData().
415 \membersection{wxImage::operator $=$
}
417 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
419 Assignment operator. This operator does not copy any data, but instead
420 passes a pointer to the data in
{\it image
} and increments a reference
421 counter. It is a fast operation.
423 \wxheading{Parameters
}
425 \docparam{image
}{Image to assign.
}
427 \wxheading{Return value
}
429 Returns 'this' object.
431 \membersection{wxImage::operator $==$
}
433 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
435 Equality operator. This operator tests whether the internal data pointers are
438 \wxheading{Parameters
}
440 \docparam{image
}{Image to compare with 'this'
}
442 \wxheading{Return value
}
444 Returns TRUE if the images were effectively equal, FALSE otherwise.
446 \membersection{wxImage::operator $!=$
}
448 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
450 Inequality operator. This operator tests whether the internal data pointers are
451 unequal (a fast test).
453 \wxheading{Parameters
}
455 \docparam{image
}{Image to compare with 'this'
}
457 \wxheading{Return value
}
459 Returns TRUE if the images were unequal, FALSE otherwise.
461 \section{\class{wxImageHandler
}}\label{wximagehandler
}
463 This is the base class for implementing image file loading/saving, and image creation from data.
464 It is used within wxImage and is not normally seen by the application.
466 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
467 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
468 application initialisation.
470 \wxheading{Note (Legal Issue)
}
472 This software is based in part on the work of the Independent JPEG Group.
474 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
477 \wxheading{Derived from
}
479 \helpref{wxObject
}{wxobject
}
481 \wxheading{Include files
}
487 \helpref{wxImage
}{wximage
}
489 \latexignore{\rtfignore{\wxheading{Members
}}}
491 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
493 \func{}{wxImageHandler
}{\void}
495 Default constructor. In your own default constructor, initialise the members
496 m
\_name, m
\_extension and m
\_type.
498 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
500 \func{}{\destruct{wxImageHandler
}}{\void}
502 Destroys the wxImageHandler object.
504 \membersection{wxImageHandler::GetName
}
506 \constfunc{wxString
}{GetName
}{\void}
508 Gets the name of this handler.
510 \membersection{wxImageHandler::GetExtension
}
512 \constfunc{wxString
}{GetExtension
}{\void}
514 Gets the file extension associated with this handler.
516 \membersection{wxImageHandler::GetType
}
518 \constfunc{long
}{GetType
}{\void}
520 Gets the image type associated with this handler.
522 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
524 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
526 Loads a image from a stream, putting the resulting data into
{\it image
}.
528 \wxheading{Parameters
}
530 \docparam{image
}{The image object which is to be affected by this operation.
}
532 \docparam{stream
}{Opened input stream.
533 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
535 \wxheading{Return value
}
537 TRUE if the operation succeeded, FALSE otherwise.
541 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
542 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
543 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
545 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
547 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
549 Saves a image in the output stream.
551 \wxheading{Parameters
}
553 \docparam{image
}{The image object which is to be affected by this operation.
}
555 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
557 \wxheading{Return value
}
559 TRUE if the operation succeeded, FALSE otherwise.
563 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
564 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
565 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
567 \membersection{wxImageHandler::SetName
}
569 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
571 Sets the handler name.
573 \wxheading{Parameters
}
575 \docparam{name
}{Handler name.
}
577 \membersection{wxImageHandler::SetExtension
}
579 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
581 Sets the handler extension.
583 \wxheading{Parameters
}
585 \docparam{extension
}{Handler extension.
}
587 \membersection{wxImageHandler::SetType
}
589 \func{void
}{SetType
}{\param{long
}{type
}}
591 Sets the handler type.
593 \wxheading{Parameters
}
595 \docparam{name
}{Handler type.
}