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
75 Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
76 initialization in order to work with JPEGs.
80 \helpref{wxImage::LoadFile
}{wximageloadfile
}
82 \membersection{wxImage::
\destruct{wxImage
}}
84 \func{}{\destruct{wxImage
}}{\void}
88 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
90 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
92 Adds a handler to the end of the static list of format handlers.
94 \docparam{handler
}{A new image format handler object. There is usually only one instance
95 of a given handler class in an application session.
}
99 \helpref{wxImageHandler
}{wximagehandler
}
101 \membersection{wxImage::CleanUpHandlers
}
103 \func{static void
}{CleanUpHandlers
}{\void}
105 Deletes all image handlers.
107 This function is called by wxWindows on exit.
109 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
111 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
113 Converts the image to a platform-specific bitmap object. This has to be done
114 to actually display an image as you cannot draw an image directly on a window.
115 The resulting bitmap will use the colour depth of the current system which entails
116 that a (crude) colour reduction has to take place. When in
8-bit mode, this
117 routine will use a
color cube created on program start-up to look up colors.
118 Still, the image quality won't be perfect for photo images.
120 \membersection{wxImage::Create
}\label{wximagecreate
}
122 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
}}
124 Creates a fresh image.
126 \wxheading{Parameters
}
128 \docparam{width
}{The width of the image in pixels.
}
130 \docparam{height
}{The height of the image in pixels.
}
132 \wxheading{Return value
}
134 TRUE if the call succeeded, FALSE otherwise.
136 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
138 \func{bool
}{Destroy
}{\void}
140 Destroys the image data.
142 \membersection{wxImage::FindHandler
}
144 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
146 Finds the handler with the given name.
148 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
150 Finds the handler associated with the given extension and type.
152 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
154 Finds the handler associated with the given image type.
156 \docparam{name
}{The handler name.
}
158 \docparam{extension
}{The file extension, such as ``bmp".
}
160 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
162 \wxheading{Return value
}
164 A pointer to the handler if found, NULL otherwise.
168 \helpref{wxImageHandler
}{wximagehandler
}
170 \membersection{wxImage::GetBlue
}\label{wximagegetblue
}
172 \constfunc{unsigned char
}{GetBlue
}{\param{int
}{ x
},
\param{int
}{ y
}}
174 Returns the blue intensity at the given coordinate.
176 \membersection{wxImage::GetData
}\label{wximagegetdata
}
178 \constfunc{unsigned char*
}{GetData
}{\void}
180 Returns the image data as an array. This is most often used when doing
181 direct image manipulation. The return value points to an array of
182 chararcters in RGBGBRGB... format.
184 \membersection{wxImage::GetGreen
}\label{wximagegetgreen
}
186 \constfunc{unsigned char
}{GetGreen
}{\param{int
}{ x
},
\param{int
}{ y
}}
188 Returns the green intensity at the given coordinate.
190 \membersection{wxImage::GetRed
}\label{wximagegetred
}
192 \constfunc{unsigned char
}{GetRed
}{\param{int
}{ x
},
\param{int
}{ y
}}
194 Returns the red intensity at the given coordinate.
196 \membersection{wxImage::GetHandlers
}
198 \func{static wxList\&
}{GetHandlers
}{\void}
200 Returns the static list of image format handlers.
204 \helpref{wxImageHandler
}{wximagehandler
}
206 \membersection{wxImage::GetHeight
}\label{wximagegetheight
}
208 \constfunc{int
}{GetHeight
}{\void}
210 Gets the height of the image in pixels.
212 \membersection{wxImage::GetMaskBlue
}\label{wximagegetmaskblue
}
214 \constfunc{unsigned char
}{GetMaskBlue
}{\void}
216 Gets the blue value of the mask colour.
218 \membersection{wxImage::GetMaskGreen
}\label{wximagegetmaskgreen
}
220 \constfunc{unsigned char
}{GetMaskGreen
}{\void}
222 Gets the green value of the mask colour.
224 \membersection{wxImage::GetMaskRed
}\label{wximagegetmaskred
}
226 \constfunc{unsigned char
}{GetMaskRed
}{\void}
228 Gets the red value of the mask colour.
230 \membersection{wxImage::GetWidth
}\label{wximagegetwidth
}
232 \constfunc{int
}{GetWidth
}{\void}
234 Gets the width of the image in pixels.
238 \helpref{wxImage::GetHeight
}{wximagegetheight
}
240 \membersection{wxImage::HasMask
}\label{wximagehasmask
}
242 \constfunc{bool
}{HasMask
}{\void}
244 Returns TRUE if there is a mask active, FALSE otherwise.
246 \membersection{wxImage::InitStandardHandlers
}
248 \func{static void
}{InitStandardHandlers
}{\void}
250 Adds the standard image format handlers, which, depending on wxWindows
251 configuration, can be handlers for Windows BMP (loading), PNG
252 (loading and saving) and JPEG (loading and saving) file formats.
254 This function is called by wxWindows on startup.
258 \helpref{wxImageHandler
}{wximagehandler
}
260 \membersection{wxImage::InsertHandler
}
262 \func{static void
}{InsertHandler
}{\param{wxImageHandler*
}{ handler
}}
264 Adds a handler at the start of the static list of format handlers.
266 \docparam{handler
}{A new image format handler object. There is usually only one instance
267 of a given handler class in an application session.
}
271 \helpref{wxImageHandler
}{wximagehandler
}
273 \membersection{wxImage::LoadFile
}\label{wximageloadfile
}
275 \func{bool
}{LoadFile
}{\param{const wxString\&
}{ name
},
\param{long
}{ type
}}
277 Loads an image from a file.
279 \func{bool
}{LoadFile
}{\param{wxInputStream\&
}{ stream
},
\param{long
}{ type
}}
281 Loads an image from an input stream.
283 \wxheading{Parameters
}
285 \docparam{name
}{A filename.
286 The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
288 \docparam{stream
}{An input stream.
289 The meaning of
{\it stream
} data is determined by the
{\it type
} parameter.
}
291 \docparam{type
}{One of the following values:
295 \twocolitem{{\bf wxBITMAP
\_TYPE\_BMP}}{Load a Windows image file.
}
296 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Load a PNG image file.
}
297 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG image file.
}
300 The validity of these flags depends on the platform and wxWindows configuration.
}
302 \wxheading{Return value
}
304 TRUE if the operation succeeded, FALSE otherwise.
308 \helpref{wxImage::SaveFile
}{wximagesavefile
}
310 \membersection{wxImage::Ok
}\label{wximageok
}
312 \constfunc{bool
}{Ok
}{\void}
314 Returns TRUE if image data is present.
316 \membersection{wxImage::RemoveHandler
}
318 \func{static bool
}{RemoveHandler
}{\param{const wxString\&
}{name
}}
320 Finds the handler with the given name, and removes it. The handler
323 \docparam{name
}{The handler name.
}
325 \wxheading{Return value
}
327 TRUE if the handler was found and removed, FALSE otherwise.
331 \helpref{wxImageHandler
}{wximagehandler
}
333 \membersection{wxImage::SaveFile
}\label{wximagesavefile
}
335 \func{bool
}{SaveFile
}{\param{const wxString\&
}{name
},
\param{int
}{ type
}}
337 Saves a image in the named file.
339 \func{bool
}{SaveFile
}{\param{wxOutputStream\&
}{stream
},
\param{int
}{ type
}}
341 Saves a image in the given stream.
343 \wxheading{Parameters
}
345 \docparam{name
}{A filename. The meaning of
{\it name
} is determined by the
{\it type
} parameter.
}
347 \docparam{stream
}{An output stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
349 \docparam{type
}{Currently two types can be used:
353 \twocolitem{{\bf wxBITMAP
\_TYPE\_PNG}}{Save a PNG image file.
}
354 \twocolitem{{\bf wxBITMAP
\_TYPE\_JPEG}}{Save a JPEG image file.
}
357 The validity of these flags depends on the platform and wxWindows configuration
358 as well as user-added handlers.
}
360 \wxheading{Return value
}
362 TRUE if the operation succeeded, FALSE otherwise.
366 Depending on how wxWindows has been configured, not all formats may be available.
370 \helpref{wxImage::LoadFile
}{wximageloadfile
}
372 \membersection{wxImage::Scale
}\label{wximagescale
}
374 \func{wxImage
}{Scale
}{\param{int
}{ width
},
\param{int
}{ height
}}
376 Returns a scaled version of the image. This is also useful for
377 scaling bitmaps in general as the only other way to scale bitmaps
378 is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such
379 scaling itself but in the GTK port, scaling bitmaps is done using
380 this routine internally.
382 \membersection{wxImage::SetData
}\label{wximagesetdata
}
384 \func{void
}{SetData
}{\param{unsigned char*
}{data
}}
386 Sets the image data without performing checks. The data given must have
387 the size (width*height*
3) or results will be unexpected. Don't use this
388 method if you aren't sure you know what you are doing.
390 \membersection{wxImage::SetMask
}\label{wximagesetmask
}
392 \func{void
}{SetMask
}{\param{bool
}{ hasMask = TRUE
}}
394 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
396 \membersection{wxImage::SetMaskColour
}\label{wximagesetmaskcolour
}
398 \func{void
}{SetMaskColour
}{\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
400 Sets the mask colour for this image (and tells the image to use the mask).
402 \membersection{wxImage::SetRGB
}\label{wximagesetrgb
}
404 \func{void
}{SetRGB
}{\param{int
}{x
},
\param{int
}{y
},
\param{unsigned char
}{red
},
\param{unsigned char
}{blue
},
\param{unsigned char
}{green
}}
406 Sets the pixel at the given coordinate. This routine performs bounds-checks
407 for the coordinate so it can be considered a safe way to manipulate the
408 data, but in some cases this might be too slow so that the data will have to
409 be set directly. In that case you have to get that data by calling GetData().
411 \membersection{wxImage::operator $=$
}
413 \func{wxImage\&
}{operator $=$
}{\param{const wxImage\&
}{image
}}
415 Assignment operator. This operator does not copy any data, but instead
416 passes a pointer to the data in
{\it image
} and increments a reference
417 counter. It is a fast operation.
419 \wxheading{Parameters
}
421 \docparam{image
}{Image to assign.
}
423 \wxheading{Return value
}
425 Returns 'this' object.
427 \membersection{wxImage::operator $==$
}
429 \func{bool
}{operator $==$
}{\param{const wxImage\&
}{image
}}
431 Equality operator. This operator tests whether the internal data pointers are
434 \wxheading{Parameters
}
436 \docparam{image
}{Image to compare with 'this'
}
438 \wxheading{Return value
}
440 Returns TRUE if the images were effectively equal, FALSE otherwise.
442 \membersection{wxImage::operator $!=$
}
444 \func{bool
}{operator $!=$
}{\param{const wxImage\&
}{image
}}
446 Inequality operator. This operator tests whether the internal data pointers are
447 unequal (a fast test).
449 \wxheading{Parameters
}
451 \docparam{image
}{Image to compare with 'this'
}
453 \wxheading{Return value
}
455 Returns TRUE if the images were unequal, FALSE otherwise.
457 \section{\class{wxImageHandler
}}\label{wximagehandler
}
459 This is the base class for implementing image file loading/saving, and image creation from data.
460 It is used within wxImage and is not normally seen by the application.
462 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
463 and add the handler using
\helpref{wxImage::AddHandler
}{wximageaddhandler
} in your
464 application initialisation.
466 \wxheading{Note (Legal Issue)
}
468 This software is based in part on the work of
469 the Independent JPEG Group.
471 (Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
474 \wxheading{Derived from
}
476 \helpref{wxObject
}{wxobject
}
480 \helpref{wxImage
}{wximage
}
482 \latexignore{\rtfignore{\wxheading{Members
}}}
484 \membersection{wxImageHandler::wxImageHandler
}\label{wximagehandlerconstr
}
486 \func{}{wxImageHandler
}{\void}
488 Default constructor. In your own default constructor, initialise the members
489 m
\_name, m
\_extension and m
\_type.
491 \membersection{wxImageHandler::
\destruct{wxImageHandler
}}
493 \func{}{\destruct{wxImageHandler
}}{\void}
495 Destroys the wxImageHandler object.
497 \membersection{wxImageHandler::GetName
}
499 \constfunc{wxString
}{GetName
}{\void}
501 Gets the name of this handler.
503 \membersection{wxImageHandler::GetExtension
}
505 \constfunc{wxString
}{GetExtension
}{\void}
507 Gets the file extension associated with this handler.
509 \membersection{wxImageHandler::GetType
}
511 \constfunc{long
}{GetType
}{\void}
513 Gets the image type associated with this handler.
515 \membersection{wxImageHandler::LoadFile
}\label{wximagehandlerloadfile
}
517 \func{bool
}{LoadFile
}{\param{wxImage*
}{image
},
\param{wxInputStream\&
}{ stream
}}
519 Loads a image from a stream, putting the resulting data into
{\it image
}.
521 \wxheading{Parameters
}
523 \docparam{image
}{The image object which is to be affected by this operation.
}
525 \docparam{stream
}{Opened input stream.
526 The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
528 \wxheading{Return value
}
530 TRUE if the operation succeeded, FALSE otherwise.
534 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
535 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
536 \helpref{wxImageHandler::SaveFile
}{wximagehandlersavefile
}
538 \membersection{wxImageHandler::SaveFile
}\label{wximagehandlersavefile
}
540 \func{bool
}{SaveFile
}{\param{wxImage*
}{image
},
\param{wxOutputStream\&
}{stream
}}
542 Saves a image in the output stream.
544 \wxheading{Parameters
}
546 \docparam{image
}{The image object which is to be affected by this operation.
}
548 \docparam{stream
}{A stream. The meaning of
{\it stream
} is determined by the
{\it type
} parameter.
}
550 \wxheading{Return value
}
552 TRUE if the operation succeeded, FALSE otherwise.
556 \helpref{wxImage::LoadFile
}{wximageloadfile
}\\
557 \helpref{wxImage::SaveFile
}{wximagesavefile
}\\
558 \helpref{wxImageHandler::LoadFile
}{wximagehandlerloadfile
}
560 \membersection{wxImageHandler::SetName
}
562 \func{void
}{SetName
}{\param{const wxString\&
}{name
}}
564 Sets the handler name.
566 \wxheading{Parameters
}
568 \docparam{name
}{Handler name.
}
570 \membersection{wxImageHandler::SetExtension
}
572 \func{void
}{SetExtension
}{\param{const wxString\&
}{extension
}}
574 Sets the handler extension.
576 \wxheading{Parameters
}
578 \docparam{extension
}{Handler extension.
}
580 \membersection{wxImageHandler::SetType
}
582 \func{void
}{SetType
}{\param{long
}{type
}}
584 Sets the handler type.
586 \wxheading{Parameters
}
588 \docparam{name
}{Handler type.
}