📄 image.tex
字号:
\wxheading{See also}\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp\helpref{wxImage::GetOption}{wximagegetoption},\rtfsp\helpref{wxImage::GetOptionInt}{wximagegetoptionint}\membersection{wxImage::InitAlpha}\label{wximageinitalpha}\func{void}{InitAlpha}{\void}Initializes the image alpha channel data. It is an error to call itif the image already has alpha data. If it doesn't, alpha data will beby default initialized to all pixels being fully opaque. But if the image has aa mask colour, all mask pixels will be completely transparent.\membersection{wxImage::InitStandardHandlers}\label{wximageinitstandardhandlers}\func{static void}{InitStandardHandlers}{\void}Internal use only. Adds standard image format handlers. It only install BMPfor the time being, which is used by wxBitmap.This function is called by wxWidgets on startup, and shouldn't be called bythe user.\wxheading{See also}\helpref{wxImageHandler}{wximagehandler},\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}\membersection{wxImage::InsertHandler}\label{wximageinserthandler}\func{static void}{InsertHandler}{\param{wxImageHandler*}{ handler}}Adds a handler at the start 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}\membersection{wxImage::IsTransparent}\label{wximageistransparent}\constfunc{bool}{IsTransparent}{\param{int }{x}, \param{int }{y}, \param{unsigned char}{ threshold = $128$}}Returns \true if the given pixel is transparent, i.e. either has the maskcolour if this image has a mask or if this image has alpha channel and alphavalue of this pixel is strictly less than \arg{threshold}.\membersection{wxImage::LoadFile}\label{wximageloadfile}\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}Loads an image from a file. If no handler type is provided, the library willtry to autodetect the format.\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{long}{ type}, \param{int}{ index = -1}}\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}Loads an image from an input stream.\wxheading{Parameters}\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}{One of the following values:\twocolwidtha{5cm}%\begin{twocollist}\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Load a GIF image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Load a JPEG image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_PCX}}{Load a PCX image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Load a PNG image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_PNM}}{Load a PNM image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_TIF}}{Load a TIFF image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Load a XPM image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}\twocolitem{{\bf wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}\twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}\twocolitem{{\bf 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.}\wxheading{Remarks}Depending on how wxWidgets has been configured, not all formats may be available.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{Return value}true if the operation succeeded, false otherwise. If the optional index parameter is out of range,false is returned and a call to wxLogError() takes place.\wxheading{See also}\helpref{wxImage::SaveFile}{wximagesavefile}\pythonnote{In place of a single overloaded method name, wxPythonimplements the following methods:\par\indented{2cm}{\begin{twocollist}\twocolitem{{\bf LoadFile(filename, type)}}{Loads an image of the giventype from a file}\twocolitem{{\bf LoadMimeFile(filename, mimetype)}}{Loads an image of the givenmimetype from a file}\end{twocollist}}}\perlnote{Methods supported by wxPerl are:\par\begin{itemize}\item{bitmap->LoadFile( name, type )}\item{bitmap->LoadFile( name, mimetype )}\end{itemize}}\membersection{wxImage::IsOk}\label{wximageisok}\constfunc{bool}{IsOk}{\void}Returns true if image data is present.\membersection{RGBValue::RGBValue}\label{rgbvaluergbvalue}\func{}{RGBValue}{\param{unsigned char }{r = 0}, \param{unsigned char }{g = 0}, \param{unsigned char }{b = 0}}Constructor for RGBValue, an object that contains values for red, green and blue whichrepresent the value of a color. It is used by \helpref{wxImage::HSVtoRGB}{wximagehsvtorgb}and \helpref{wxImage::RGBtoHSV}{wximagergbtohsv}, whichconverts between HSV color space and RGB color space.\pythonnote{use wxImage\_RGBValue in wxPython}\membersection{wxImage::RGBtoHSV}\label{wximagergbtohsv}\func{wxImage::HSVValue}{RGBtoHSV}{\param{const RGBValue\& }{rgb}}Converts a color in RGB color space to HSV color space.\membersection{wxImage::RemoveHandler}\label{wximageremovehandler}\func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}Finds the handler with the given name, and removes it. The handleris not deleted.\docparam{name}{The handler name.}\wxheading{Return value}true if the handler was found and removed, false otherwise.\wxheading{See also}\helpref{wxImageHandler}{wximagehandler}\membersection{wxImage::Mirror}\label{wximagemirror}\constfunc{wxImage}{Mirror}{\param{bool}{ horizontally = true}}Returns a mirrored copy of the image. The parameter {\it horizontally}indicates the orientation.\membersection{wxImage::Replace}\label{wximagereplace}\func{void}{Replace}{\param{unsigned char}{ r1}, \param{unsigned char}{ g1}, \param{unsigned char}{ b1},\param{unsigned char}{ r2}, \param{unsigned char}{ g2}, \param{unsigned char}{ b2}}Replaces the colour specified by {\it r1,g1,b1} by the colour {\it r2,g2,b2}.\membersection{wxImage::Rescale}\label{wximagerescale}\func{wxImage \&}{Rescale}{\param{int}{ width}, \param{int}{ height}, \param{int}{ quality = wxIMAGE\_QUALITY\_NORMAL}}Changes the size of the image in-place by scaling it: after a call to this function,the image will have the given width and height.For a description of the {\it quality} parameter, see the \helpref{Scale}{wximagescale} function.Returns the (modified) image itself.\wxheading{See also}\helpref{Scale}{wximagescale}\membersection{wxImage::Resize}\label{wximageresize}\func{wxImage \&}{Resize}{\param{const wxSize\&}{ size}, \param{const wxPoint&}{ pos}, \param{int}{ red = -1}, \param{int}{ green = -1}, \param{int}{ blue = -1}}Changes the size of the image in-place without scaling it by adding either a borderwith the given colour or cropping as necessary. The image is pasted into a newimage with the given {\it size} and background colour at the position {\it pos}relative to the upper left of the new image. If {\it red = green = blue = -1}then use either the current mask colour if set or find, use, and set asuitable mask colour for any newly exposed areas.Returns the (modified) image itself.\wxheading{See also}\helpref{Size}{wximagesize}\membersection{wxImage::Rotate}\label{wximagerotate}\func{wxImage}{Rotate}{\param{double}{ angle}, \param{const wxPoint\& }{rotationCentre}, \param{bool}{ interpolating = true}, \param{wxPoint*}{ offsetAfterRotation = NULL}}Rotates the image about the given point, by {\it angle} radians. Passing trueto {\it interpolating} results in better image quality, but is slower. If theimage has a mask, then the mask colour is used for the uncovered pixels in therotated image background. Else, black (rgb 0, 0, 0) will be used.Returns the rotated image, leaving this image intact.\membersection{wxImage::RotateHue}\label{wximagerotatehue}\func{void}{RotateHue}{\param{double}{ angle}}Rotates the hue of each pixel in the image by {\it angle}, which is a double inthe range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 correspondsto +360 degrees.\membersection{wxImage::Rotate90}\label{wximagerotate90}\constfunc{wxImage}{Rotate90}{\param{bool}{ clockwise = true}}Returns a copy of the image rotated 90 degrees in the directionindicated by {\it clockwise}.\membersection{wxImage::SaveFile}\label{wximagesavefile}\constfunc{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}\constfunc{bool}{SaveFile}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}Saves an image in the named file.\constfunc{bool}{SaveFile}{\param{const wxString\& }{name}}Saves an image in the named file. File type is determined from the extension of thefile name. Note that this function may fail if the extension is not recognized! Youcan use one of the forms above to save images to files with non-standard extensions.\constfunc{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{int}{ type}}\constfunc{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{const wxString\&}{ mimetype}}Saves an image in the given stream.\wxheading{Parameters}\docparam{name}{Name of the file to save the image to.}\docparam{stream}{Opened output stream to save the image to.}\docparam{type}{Currently these types can be used:\twocolwidtha{5cm}%\begin{twocollist}\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Save a BMP image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Save a JPEG image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Save a PNG image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_PCX}}{Save a PCX image file (tries to save as 8-bit if possible, falls back to 24-bit otherwise).}\twocolitem{{\bf wxBITMAP\_TYPE\_PNM}}{Save a PNM image file (as raw RGB always).}\twocolitem{{\bf wxBITMAP\_TYPE\_TIFF}}{Save a TIFF image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Save a XPM image file.}\twocolitem{{\bf wxBITMAP\_TYPE\_ICO}}{Save a Windows icon file (ICO) (the size may be up to 255 wide by 127 high. A single image is saved in 8 colors at the size supplied).}\twocolitem{{\bf wxBITMAP\_TYPE\_CUR}}{Save a Windows cursor file (CUR).}\end{twocollist}}\docparam{mimetype}{MIME type.}\wxheading{Return value}true if the operation succeeded, false otherwise.\wxheading{Remarks}Depending on how wxWidgets has been configured, not all formats may be available.Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to set thehotspot before saving an image into a cursor file (default hotspot is inthe centre of the image):\begin{verbatim} image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX); image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);\end{verbatim}\wxheading{See also}\helpref{wxImage::LoadFile}{wximageloadfile}\pythonnote{In place of a single overloaded method name, wxPythonimplements the following methods:\par\indented{2cm}{\begin{twocollist}\twocolitem{{\bf SaveFile(filename, type)}}{Saves the image using the giventype to the named file}\twocolitem{{\bf SaveMimeFile(filename, mimetype)}}{Saves the image using the givenmimetype to the named file}\end{twocollist}}}\perlnote{Methods supported by wxPerl are:\par\begin{itemize}\item{bitmap->SaveFile( name, type )}\item{bitmap->SaveFile( name, mimetype )}\end{itemize}}\membersection{wxImage::Scale}\label{wximagescale}\constfunc{wxImage}{Scale}{\param{int}{ width}, \param{int}{ height}, \param{int}{ quality = wxIMAGE\_QUALITY\_NORMAL}}Returns a scaled version of the image. This is also useful forscaling bitmaps in general as the only other way to scale bitmapsis to blit a wxMemoryDC into another wxMemoryDC.\docparam{quality}{Determines what method to use for resampling the image. Can be one of the following:\twocolwidtha{5cm}%\begin{twocollist}\twocolitem{{\bf wxIMAGE\_QUALITY\_NORMAL}}{Uses the normal default scaling method of pixel replication}\twocolitem{{\bf wxIMAGE\_QUALITY\_HIGH}}{Uses bicubic and box averaging resampling methods for upsampling and downsampling respectively}\end{twocollist}}It should be noted that although using wxIMAGE\_QUALITY\_HIGH produces much nicerlooking results it is a slower method. Downsampling will use the box averaging methodwhich seems to operate very fast. If you are upsampling larger images usingthis method you will most likely notice that it is a bit slower and in extreme casesit will be quite substantially slower as the bicubic algorithm has to process a lot ofdata.It should also be noted that the high quality scaling may not work as expected
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -