📄 image.tex
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Name: image.tex%% Purpose: wxImage documentation%% Author: wxWidgets Team%% Modified by:%% Created:%% RCS-ID: $Id: image.tex,v 1.94 2006/10/30 19:25:50 VZ Exp $%% Copyright: (c) wxWidgets Team%% License: wxWindows license%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\section{\class{wxImage}}\label{wximage}This class encapsulates a platform-independent image. An image can be createdfrom data, or using \helpref{wxBitmap::ConvertToImage}{wxbitmapconverttoimage}. An imagecan be loaded from a file in a variety of formats, and is extensible to new formatsvia image format handlers. Functions are available to set and get image bits, soit can be used for basic image manipulation.A wxImage cannot (currently) be drawn directly to a \helpref{wxDC}{wxdc}. Instead,a platform-specific \helpref{wxBitmap}{wxbitmap} object must be created from it usingthe \helpref{wxBitmap::wxBitmap(wxImage,int depth)}{wxbitmapctor} constructor.This bitmap can thenbe drawn in a device context, using \helpref{wxDC::DrawBitmap}{wxdcdrawbitmap}.One colour value of the image may be used as a mask colour which will lead to the automaticcreation of a \helpref{wxMask}{wxmask} object associated to the bitmap object.\wxheading{Alpha channel support}Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is inaddition to a byte for the red, green and blue colour components for each pixelit also stores a byte representing the pixel opacity. An alpha value of $0$corresponds to a transparent pixel (null opacity) while a value of $255$means that the pixel is 100\% opaque.Unlike RGB data, not all images have an alpha channel and before using\helpref{GetAlpha}{wximagegetalpha} you should check if this image containsan alpha channel with \helpref{HasAlpha}{wximagehasalpha}. Note that currently onlyimages loaded from PNG files with transparency information will have an alphachannel but alpha support will be added to the other formats as well (as wellas support for saving images with alpha channel which also isn't implemented).\wxheading{Available image handlers}The following image handlers are available. {\bf wxBMPHandler} is alwaysinstalled by default. To use other image formats, install the appropriatehandler with \helpref{wxImage::AddHandler}{wximageaddhandler} or call \helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}.\twocolwidtha{5cm}%\begin{twocollist}\twocolitem{\indexit{wxBMPHandler}}{For loading and saving, always installed.}\twocolitem{\indexit{wxPNGHandler}}{For loading (including alpha support) and saving.}\twocolitem{\indexit{wxJPEGHandler}}{For loading and saving.}\twocolitem{\indexit{wxGIFHandler}}{Only for loading, due to legal issues.}\twocolitem{\indexit{wxPCXHandler}}{For loading and saving (see below).}\twocolitem{\indexit{wxPNMHandler}}{For loading and saving (see below).}\twocolitem{\indexit{wxTIFFHandler}}{For loading and saving.}\twocolitem{\indexit{wxTGAHandler}}{For loading only.}\twocolitem{\indexit{wxIFFHandler}}{For loading only.}\twocolitem{\indexit{wxXPMHandler}}{For loading and saving.}\twocolitem{\indexit{wxICOHandler}}{For loading and saving.}\twocolitem{\indexit{wxCURHandler}}{For loading and saving.}\twocolitem{\indexit{wxANIHandler}}{For loading only.}\end{twocollist}When saving in PCX format, {\bf wxPCXHandler} will count the number ofdifferent colours in the image; if there are 256 or less colours, it willsave as 8 bit, else it will save as 24 bit.Loading PNMs only works for ASCII or raw RGB images. When saving inPNM format, {\bf wxPNMHandler} will always save as raw RGB.\wxheading{Derived from}\helpref{wxObject}{wxobject}\wxheading{Include files}<wx/image.h>\wxheading{See also}\helpref{wxBitmap}{wxbitmap},\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}\latexignore{\rtfignore{\wxheading{Members}}}\membersection{wxImage::wxImage}\label{wximagector}\func{}{wxImage}{\void}Default constructor.\func{}{wxImage}{\param{const wxImage\& }{image}}Copy constructor, uses \helpref{reference counting}{trefcount}.\func{}{wxImage}{\param{const wxBitmap\&}{ bitmap}}(Deprecated form, use \helpref{wxBitmap::ConvertToImage}{wxbitmapconverttoimage}instead.) Constructs an image from a platform-dependent bitmap. This preservesmask information so that bitmaps and images can be converted backand forth without loss in that respect.\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}Creates an image with the given width and height. If {\it clear} is true, the new image will be initialized to black.Otherwise, the image data will be uninitialized.\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data = \false}}Creates an image from given data with the given width and height. If{\it static\_data} is true, then wxImage will not delete the actualimage data in its destructor, otherwise it will free it by calling{\it free()}.\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}\func{}{wxImage}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}Loads an image from a file.\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}Loads an image from an input stream.\func{}{wxImage}{\param{const char* const* }{xpmData}}Creates an image from XPM data.\wxheading{Parameters}\docparam{width}{Specifies the width of the image.}\docparam{height}{Specifies the height of the image.}\docparam{name}{Name of the file from which to load the image.}\docparam{stream}{Opened input stream from which to load the image. Currently, the stream must support seeking.}\docparam{type}{May be one of the following:\twocolwidtha{5cm}%\begin{twocollist}\twocolitem{\indexit{wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_JPEG}}{Load a JPEG bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_PNG}}{Load a PNG bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_PCX}}{Load a PCX bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_PNM}}{Load a PNM bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_TIF}}{Load a TIFF bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_TGA}}{Load a TGA bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_XPM}}{Load a XPM bitmap file.}\twocolitem{\indexit{wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}\twocolitem{\indexit{wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}\twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}\twocolitem{\indexit{wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}\end{twocollist}}\docparam{mimetype}{MIME type string (for example 'image/jpeg')}\docparam{index}{Index of the image to load in the case that the image file contains multiple images.This is only used by GIF, ICO and TIFF handlers. The default value (-1) means"choose the default image" and is interpreted as the first image (index=0) bythe GIF and TIFF handler and as the largest and most colourful one by the ICO handler.}\docparam{xpmData}{A pointer to XPM image data.}\wxheading{Remarks}Depending on how wxWidgets has been configured, not all formats may be available.Note: any handler other than BMP must be previouslyinitialized with \helpref{wxImage::AddHandler}{wximageaddhandler} or\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}.Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get thehotspot for loaded cursor file:\begin{verbatim} int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);\end{verbatim}\wxheading{See also}\helpref{wxImage::LoadFile}{wximageloadfile}\pythonnote{Constructors supported by wxPython are:\par\indented{2cm}{\begin{twocollist}\twocolitem{{\bf wxImage(name, flag)}}{Loads an image from a file}\twocolitem{{\bf wxNullImage()}}{Create a null image (has no size orimage data)}\twocolitem{{\bf wxEmptyImage(width, height)}}{Creates an empty imageof the given size}\twocolitem{{\bf wxImageFromMime(name, mimetype}}{Creates an image fromthe given file of the given mimetype}\twocolitem{{\bf wxImageFromBitmap(bitmap)}}{Creates an image from aplatform-dependent bitmap}\end{twocollist}}}\perlnote{Constructors supported by wxPerl are:\par\begin{itemize}\item{Wx::Image->new( bitmap )}\item{Wx::Image->new( icon )}\item{Wx::Image->new( width, height )}\item{Wx::Image->new( width, height, data )}\item{Wx::Image->new( file, type, index )}\item{Wx::Image->new( file, mimetype, index )}\item{Wx::Image->new( stream, type, index )}\item{Wx::Image->new( stream, mimetype, index )}\end{itemize}}\membersection{wxImage::\destruct{wxImage}}\label{wximagedtor}\func{}{\destruct{wxImage}}{\void}Destructor.See \helpref{reference-counted object destruction}{refcountdestruct} for more info.\membersection{wxImage::AddHandler}\label{wximageaddhandler}\func{static void}{AddHandler}{\param{wxImageHandler*}{ handler}}Adds a handler to the end of the static list of format handlers.\docparam{handler}{A new image format handler object. There is usually only one instanceof a given handler class in an application session.}\wxheading{See also}\helpref{wxImageHandler}{wximagehandler}\func{bool}{CanRead}{\param{const wxString\&}{ filename}}returns true if the current image handlers can read this file\pythonnote{In wxPython this static method is named {\tt wxImage\_AddHandler}.}\membersection{wxImage::Blur}\label{wximageblur}\func{wxImage}{Blur}{\param{int}{ blurRadius}}Blurs the image in both horizontal and vertical directions by the specified pixel{\it blurRadius}. This should not be used when using a single mask colourfor transparency.\wxheading{See also}\helpref{BlurHorizontal}{wximagehorzblur}\helpref{BlurVertical}{wximagevertblur}\membersection{wxImage::BlurHorizontal}\label{wximagehorzblur}\func{wxImage}{BlurHorizontal}{\param{int}{ blurRadius}}Blurs the image in the horizontal direction only. This should not be usedwhen using a single mask colour for transparency.\wxheading{See also}\helpref{Blur}{wximageblur}\helpref{BlurVertical}{wximagevertblur}\membersection{wxImage::BlurVertical}\label{wximagevertblur}\func{wxImage}{BlurVertical}{\param{int}{ blurRadius}}Blurs the image in the vertical direction only. This should not be usedwhen using a single mask colour for transparency.\wxheading{See also}\helpref{Blur}{wximageblur}\helpref{BlurHorizontal}{wximagehorzblur}\membersection{wxImage::CleanUpHandlers}\label{wximagecleanuphandlers}\func{static void}{CleanUpHandlers}{\void}Deletes all image handlers.This function is called by wxWidgets on exit.\membersection{wxImage::ComputeHistogram}\label{wximagecomputehistogram}\constfunc{unsigned long}{ComputeHistogram}{\param{wxImageHistogram\& }{histogram}}Computes the histogram of the image. {\it histogram} is a reference towxImageHistogram object. wxImageHistogram is a specialization of\helpref{wxHashMap}{wxhashmap} "template" and is defined as follows:\begin{verbatim}class WXDLLEXPORT wxImageHistogramEntry{public: wxImageHistogramEntry() : index(0), value(0) {} unsigned long index; unsigned long value;};WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry, wxIntegerHash, wxIntegerEqual, wxImageHistogram);\end{verbatim}\wxheading{Return value}Returns number of colours in the histogram.\membersection{wxImage::ConvertAlphaToMask}\label{wximageconvertalphatomask}\func{bool}{ConvertAlphaToMask}{\param{unsigned char}{ threshold = $128$}}If the image has alpha channel, this method converts it to mask. All pixelswith alpha value less than \arg{threshold} are replaced with mask colourand the alpha channel is removed. Mask colour is chosen automatically using\helpref{FindFirstUnusedColour}{wximagefindfirstunusedcolour}.If the image image doesn't have alpha channel,ConvertAlphaToMask does nothing.\wxheading{Return value}\false if FindFirstUnusedColour returns \false, \true otherwise.\membersection{wxImage::ConvertToBitmap}\label{wximageconverttobitmap}\constfunc{wxBitmap}{ConvertToBitmap}{\void}Deprecated, use equivalent \helpref{wxBitmap constructor}{wxbitmapctor}(which takes wxImage and depth as its arguments) instead.\membersection{wxImage::ConvertToGreyscale}\label{wximageconverttogreyscale}\constfunc{wxImage}{ConvertToGreyscale}{\param{double}{ lr = 0.299}, \param{double}{ lg = 0.587}, \param{double}{ lb = 0.114}}Returns a greyscale version of the image. The returned image uses the luminancecomponent of the original to calculate the greyscale. Defaults to usingITU-T BT.601 when converting to YUV, where every pixel equals(R * {\it lr}) + (G * {\it lg}) + (B * {\it lb}).\membersection{wxImage::ConvertToMono}\label{wxbitmapconverttomono}\constfunc{wxImage}{ConvertToMono}{\param{unsigned char}{ r}, \param{unsigned char}{ g}, \param{unsigned char}{ b}}Returns monochromatic version of the image. The returned image has whitecolour where the original has {\it (r,g,b)} colour and black coloureverywhere else.\membersection{wxImage::Copy}\label{wximagecopy}\constfunc{wxImage}{Copy}{\void}Returns an identical copy of the image.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -