wxImage(3)

๐Ÿ“ฆ
version 29.0.6 ยท 3 versions
, in ubuntu stonking

๐Ÿ’– wxImage(3) โ€” Erlang Module Definition ๐Ÿ’–

okay bestie, welcome to the wxImage glow-up page โœจ (this is the Erlang module definition, <pink>wxImage(3)</pink>, and it's a LOT, so we're doing this in parts, buckle up ๐ŸŽ€)


๐Ÿฆ‹ NAME ๐Ÿฆ‹

wxImage โ€” this class encapsulates a platform-independent image. periodt ๐Ÿ’…


โœจ DESCRIPTION โœจ

okay so first things first: you can make an image from data, or you can get one out of wxBitmap:convertToImage/1 ๐Ÿ‘‘ You can also load an image from a file in a whole bunch of formats, and it's extensible to new formats via image format handlers. And there are functions for setting and getting image bits, so yes, you can absolutely do your basic image manipulation. slay.

the tea you NEED: a wxImage cannot (currently) be drawn directly to a wxDC. like, it just can't ๐Ÿ˜ญ Instead, a platform-specific wxBitmap object has to be created from it using the wxBitmap::wxBitmap(wxImage,int depth) constructor. then that bitmap can be drawn in a device context, using wxDC:drawBitmap/4. that's the pipeline, no shortcuts ๐Ÿซถ

More on the difference between wxImage and wxBitmap, because this is the part everyone gets confused about: wxImage is just a buffer of RGB bytes with an optional buffer for the alpha bytes. It is all generic, platform independent and image file format independent code. It includes generic code for scaling, resizing, clipping, and other manipulations of the image data. OTOH, wxBitmap is intended to be a wrapper of whatever is the native image format that is quickest/easiest to draw to a DC or to be the target of the drawing operations performed on a wxMemoryDC. By splitting the responsibilities between wxImage/wxBitmap like this then it's easier to use generic code shared by all platforms and image types for generic operations and platform specific code where performance or compatibility is needed. it's giving โœจseparation of concernsโœจ honestly.

One colour value of the image may be used as a mask colour, which will lead to the automatic creation of a wxMask object associated to the bitmap object. iykyk.

๐ŸŒˆ Alpha channel support ๐ŸŒˆ

Starting from wxWidgets 2.5.0, wxImage supports alpha channel data โ€” that is, in addition to a byte for the red, green and blue colour components for each pixel, it also stores a byte representing the pixel opacity. main character energy fr fr ๐Ÿ’…

An alpha value of 0 corresponds to a transparent pixel (null opacity), while a value of 255 means that the pixel is 100% opaque. The constants ?wxIMAGE_ALPHA_TRANSPARENT and ?wxIMAGE_ALPHA_OPAQUE can be used to indicate those values in a more readable form. use them, bestie, your future self will thank you ๐Ÿ™ˆ

While all images have RGB data, not all images have an alpha channel. so before using getAlpha/3 you should check if this image contains an alpha channel with hasAlpha/1. Currently the BMP, PNG, TGA, and TIFF format handlers have full alpha channel support for loading, so if you want to use alpha you have to use one of these formats. And if you initialize the image alpha channel yourself using setAlpha/4, you should save it in either PNG, TGA, or TIFF format to avoid losing it, as these are the only handlers that currently support saving with alpha. don't lose the alpha, it would be tragic ๐Ÿ’€

๐ŸŽ€ Available image handlers ๐ŸŽ€

The following image handlers are available. wxBMPHandler is always installed by default. To use other image formats, install the appropriate handler with wxImage::AddHandler (not implemented in wx) or call ?wxInitAllImageHandlers().

  • wxBMPHandler โ€” For loading (including alpha support) and saving, always installed. the default queen ๐Ÿ‘‘
  • wxPNGHandler (not implemented in wx) โ€” For loading and saving. Includes alpha support.
  • wxJPEGHandler (not implemented in wx) โ€” For loading and saving.
  • wxGIFHandler (not implemented in wx) โ€” For loading and saving (see below).
  • wxPCXHandler (not implemented in wx) โ€” For loading and saving (see below).
  • wxPNMHandler (not implemented in wx) โ€” For loading and saving (see below).
  • wxTIFFHandler (not implemented in wx) โ€” For loading and saving. Includes alpha support.
  • wxTGAHandler (not implemented in wx) โ€” For loading and saving. Includes alpha support.
  • wxIFFHandler (not implemented in wx) โ€” For loading only.
  • wxXPMHandler (not implemented in wx) โ€” For loading and saving.
  • wxICOHandler โ€” For loading and saving.
  • wxCURHandler โ€” For loading and saving.
  • wxANIHandler โ€” For loading only.

When saving in PCX format, wxPCXHandler (not implemented in wx) will count the number of different colours in the image; if there are 256 or less colours, it will save as 8 bit, else it will save as 24 bit. it's doing the math for you, iconic ๐Ÿ’…

Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format, wxPNMHandler (not implemented in wx) will always save as raw RGB.

Saving GIFs requires images of maximum 8 bpp (see wxQuantize (not implemented in wx)), and the alpha channel converted to a mask (see convertAlphaToMask/5). Saving an animated GIF requires images of the same size (see wxGIFHandler::SaveAnimation (not implemented in wx)). yes, all of that, no cap ๐Ÿ˜ญ

Predefined objects (include wx.hrl): ?wxNullImage

See:

  • wxBitmap
  • ?wxInitAllImageHandlers()

wxWidgets docs: wxImage


๐ŸŒธ DATA TYPES ๐ŸŒธ

wxImage() :: wx:wx_object().

๐Ÿซถ FUNCTIONS ๐Ÿซถ

'Destroy'/1

'Destroy'(This) -> ok when This :: wxImage().

Destroys the image data. that's it, that's the whole function, and honestly? she's efficient โœจ


blur/2

blur(This, BlurRadius) -> wxImage()
              when This :: wxImage(), BlurRadius :: integer().

Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius. soft focus, very dreamy ๐Ÿฆ‹

โš ๏ธ This should not be used when using a single mask colour for transparency. like, just don't ๐Ÿ™ˆ

See:

  • blurHorizontal/2
  • blurVertical/2

blurHorizontal/2

blurHorizontal(This, BlurRadius) -> wxImage()
                        when This :: wxImage(), BlurRadius :: integer().

Blurs the image in the horizontal direction only. left-to-right and that's IT ๐Ÿ’…

โš ๏ธ This should not be used when using a single mask colour for transparency.

See:

  • blur/2
  • blurVertical/2

blurVertical/2

blurVertical(This, BlurRadius) -> wxImage()
                      when This :: wxImage(), BlurRadius :: integer().

Blurs the image in the vertical direction only. up and down, nothing else ๐ŸŽ€

โš ๏ธ This should not be used when using a single mask colour for transparency.

See:

  • blur/2
  • blurHorizontal/2

convertAlphaToMask/2

convertAlphaToMask(This, [Option]) -> boolean()
                            when
                                This :: wxImage(),
                                Option :: {threshold, integer()}.

If the image has alpha channel, this method converts it to mask.

If the image has an alpha channel, all pixels with alpha value less than threshold are replaced with the mask colour and the alpha channel is removed. Otherwise nothing is done. (nothing! not a single thing! she's chill like that ๐Ÿ˜Œ)

The mask colour is chosen automatically using findFirstUnusedColour/2, see the overload below if this is not appropriate.

Return: Returns true on success, false on error.


convertAlphaToMask/5

convertAlphaToMask(This, Mr, Mg, Mb, [Option]) -> boolean()
                            when
                                This :: wxImage(),
                                Mr :: integer(),
                                Mg :: integer(),
                                Mb :: integer(),
                                Option :: {threshold, integer()}.

If the image has alpha channel, this method converts it to mask using the specified colour as the mask colour. you get to pick the colour, main character choice ๐Ÿ’–

If the image has an alpha channel, all pixels with alpha value less than threshold are replaced with the mask colour and the alpha channel is removed. Otherwise nothing is done.

Since: 2.9.0

Return: Returns true on success, false on error.


convertToGreyscale/1

convertToGreyscale(This) -> wxImage() when This :: wxImage().

Returns a greyscale version of the image. no more colour, just vibes ๐Ÿฉถ (jk, greyscale is a vibe)

Since: 2.9.0


convertToGreyscale/4

convertToGreyscale(This, Weight_r, Weight_g, Weight_b) ->
                            wxImage()
                            when
                                This :: wxImage(),
                                Weight_r :: number(),
                                Weight_g :: number(),
                                Weight_b :: number().

Returns a greyscale version of the image.

The returned image uses the luminance component of the original to calculate the greyscale. Defaults to using the standard ITU-T BT.601 when converting to YUV, where every pixel equals (R * weight_r) + (G * weight_g) + (B * weight_b). math but make it cute ๐Ÿงฎโœจ


convertToMono/4

convertToMono(This, R, G, B) -> wxImage()
                       when
                           This :: wxImage(),
                           R :: integer(),
                           G :: integer(),
                           B :: integer().

Returns monochromatic version of the image.

The returned image has white colour where the original has (r,g,b) colour and black colour everywhere else. it's giving two-tone, extremely editorial ๐ŸŒˆ


copy/1

copy(This) -> wxImage() when This :: wxImage().

Returns an identical copy of this image. clone her, no notes ๐Ÿ’…


create/3

create(This, Width, Height) -> boolean()
                when
                    This :: wxImage(),
                    Width :: integer(),
                    Height :: integer();
            (This, Sz, Data) -> boolean()
                when
                    This :: wxImage(),
                    Sz :: {W :: integer(), H :: integer()},
                    Data :: binary();
            (This, Sz, [Option]) -> boolean()
                when
                    This :: wxImage(),
                    Sz :: {W :: integer(), H :: integer()},
                    Option :: {clear, boolean()}.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. (translation: same girl, different lewk ๐ŸŽ€)


create/4

create(This, Width, Height, Data) -> boolean()
                when
                    This :: wxImage(),
                    Width :: integer(),
                    Height :: integer(),
                    Data :: binary();
            (This, Width, Height, [Option]) -> boolean()
                when
                    This :: wxImage(),
                    Width :: integer(),
                    Height :: integer(),
                    Option :: {clear, boolean()};
            (This, Sz, Data, Alpha) -> boolean()
                when
                    This :: wxImage(),
                    Sz :: {W :: integer(), H :: integer()},
                    Data :: binary(),
                    Alpha :: binary().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. yes, again, she's versatile like that ๐Ÿ˜Œ


create/5

create(This, Width, Height, Data, Alpha) -> boolean()
                when
                    This :: wxImage(),
                    Width :: integer(),
                    Height :: integer(),
                    Data :: binary(),
                    Alpha :: binary().

Creates a fresh image. brand new, no baggage, fresh start energy โœจ

See new/4 for more info. ๐Ÿ‘€

Return: true if the call succeeded, false otherwise โœจ

destroy(This :: wxImage()) -> ok.

Destroys the object ๐Ÿ’€ like, it's gone gone. no takebacks.


findFirstUnusedColour(This, [Option]) -> Result

findFirstUnusedColour(This, [Option]) -> Result
                               when
                                   Result ::
                                       {Res :: boolean(),
                                        R :: integer(),
                                        G :: integer(),
                                        B :: integer()},
                                   This :: wxImage(),
                                   Option ::
                                       {startR, integer()} |
                                       {startG, integer()} |
                                       {startB, integer()}.

Finds the first colour that is never used in the image ๐ŸŽจ lowkey a scavenger hunt.

The search begins at given initial colour and continues by increasing R, G and B components (in this order) by 1 until an unused colour is found or the colour space exhausted.

The parameters r, g, b are pointers to variables to save the colour.

The parameters startR, startG, startB define the initial values of the colour. The returned colour will have RGB values equal to or greater than these.

Return: Returns false if there is no unused colour left, true on success ๐Ÿซถ

Note: This method involves computing the histogram, which is a computationally intensive operation. so likeโ€ฆ it's giving expensive, bestie, don't call it in a loop for fun ๐Ÿ˜ญ

getAlpha(This) -> binary()

Returns pointer to the array storing the alpha values for this image.

This pointer is NULL for the images without the alpha channel ๐Ÿ™ˆ if the image does have it, this pointer may be used to directly manipulate the alpha values which are stored as the RGB ones.

getAlpha(This, X, Y) -> integer()

getAlpha(This, X, Y) -> integer()
                         when This :: wxImage(), X :: integer(), Y :: integer().

Return alpha value at given pixel location ๐Ÿ‘‘ just the one, at X, Y.

getBlue(This, X, Y) -> integer()

getBlue(This, X, Y) -> integer()
                        when This :: wxImage(), X :: integer(), Y :: integer().

Returns the blue intensity at the given coordinate ๐Ÿ’™

getData(This) -> binary()

Returns the image data as an array.

This is most often used when doing direct image manipulation. The return value points to an array of characters in RGBRGBRGB... format in the top-to-bottom, left-to-right order, that is the first RGB triplet corresponds to the first pixel of the first row, the second one - to the second pixel of the first row and so on until the end of the first row, with second row following after it and so on ๐Ÿ“

You should not delete the returned pointer nor pass it to setData/4. fr fr, hands off ๐Ÿ™…โ€โ™€๏ธ

getGreen(This, X, Y) -> integer()

getGreen(This, X, Y) -> integer()
                         when This :: wxImage(), X :: integer(), Y :: integer().

Returns the green intensity at the given coordinate ๐Ÿ’š

getHeight(This) -> integer()

Gets the height of the image in pixels ๐Ÿ“

See: getWidth/1

getImageCount(Filename, [Option]) -> integer()

getImageCount(Filename, [Option]) -> integer()
                              when
                                  Filename :: unicode:chardata(),
                                  Option :: {type, wx:wx_enum()}.

If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of available images ๐Ÿ–ผ๏ธโœจ

For the overload taking the parameter filename, that's the name of the file to query. For the overload taking the parameter stream, that's the opened input stream with image data.

See wxImageHandler::GetImageCount() (not implemented in wx) for more info.

The parameter type may be one of the following values:

  • wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
  • wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
  • wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
  • wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
  • wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
  • wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
  • wxBITMAP_TYPE_TIFF: Load a TIFF bitmap file.
  • wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
  • wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
  • wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
  • wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
  • wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
  • wxBITMAP_TYPE_ANY: Will try to autodetect the format.

Return: Number of available images. For most image handlers, this is 1 (exceptions are TIFF and ICO formats as well as animated GIFs for which this function returns the number of frames in the animation) ๐ŸŽž๏ธ

getImageExtWildcard() -> unicode:charlist()

Iterates all registered wxImageHandler (not implemented in wx) objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes ๐ŸŒˆ

Return: The format of the returned string is "(*.ext1;*.ext2)|*.ext1;*.ext2". It is usually a good idea to prepend a description before passing the result to the dialog. Example:

getMaskBlue(This) -> integer()

Gets the blue value of the mask colour ๐Ÿฉต

getMaskGreen(This) -> integer()

Gets the green value of the mask colour ๐Ÿ€

getMaskRed(This) -> integer()

Gets the red value of the mask colour ๐Ÿ“

getOption(This, Name) -> unicode:charlist()

getOption(This, Name) -> unicode:charlist()
                          when This :: wxImage(), Name :: unicode:chardata().

Gets a user-defined string-valued option ๐Ÿท๏ธ

Generic options:

  • wxIMAGE_OPTION_FILENAME: The name of the file from which the image was loaded.

Options specific to wxGIFHandler (not implemented in wx):

  • wxIMAGE_OPTION_GIF_COMMENT: The comment text that is read from or written to the GIF file. In an animated GIF each frame can have its own comment. If there is only a comment in the first frame of a GIF it will not be repeated in other frames.

Return: The value of the option or an empty string if not found. Use hasOption/2 if an empty string can be a valid option value ๐Ÿ‘€

See:

  • setOption/3
  • getOptionInt/2
  • hasOption/2

getOptionInt(This, Name) -> integer()

getOptionInt(This, Name) -> integer()
                             when This :: wxImage(), Name :: unicode:chardata().

Gets a user-defined integer-valued option ๐Ÿ”ข

The function is case-insensitive to name. If the given option is not present, the function returns 0. Use hasOption/2 if 0 is a possibly valid value for the option.

Generic options:

  • wxIMAGE_OPTION_MAX_WIDTH and wxIMAGE_OPTION_MAX_HEIGHT: If either of these options is specified, the loaded image will be scaled down (preserving its aspect ratio) so that its width is less than the max width given if it is not 0 and its height is less than the max height given if it is not 0. This is typically used for loading thumbnails and the advantage of using these options compared to calling rescale/4 after loading is that some handlers (only JPEG one right now) support rescaling the image during loading which is vastly more efficient than loading the entire huge image and rescaling it later (if these options are not supported by the handler, this is still what happens however). These options must be set before calling loadFile/4 to have any effect โš ๏ธ
  • wxIMAGE_OPTION_ORIGINAL_WIDTH and wxIMAGE_OPTION_ORIGINAL_HEIGHT: These options will return the original size of the image if either wxIMAGE_OPTION_MAX_WIDTH or wxIMAGE_OPTION_MAX_HEIGHT is specified.
    • Since: 2.9.3
  • wxIMAGE_OPTION_QUALITY: JPEG quality used when saving. This is an integer in 0..100 range with 0 meaning very poor and 100 excellent (but very badly compressed). This option is currently ignored for the other formats.
  • wxIMAGE_OPTION_RESOLUTIONUNIT: The value of this option determines whether the resolution of the image is specified in centimetres or inches, see wxImageResolution enum elements.
  • wxIMAGE_OPTION_RESOLUTION, wxIMAGE_OPTION_RESOLUTIONX and wxIMAGE_OPTION_RESOLUTIONY: These options define the resolution of the image in the units corresponding to wxIMAGE_OPTION_RESOLUTIONUNIT options value. The first option can be set before saving the image to set both horizontal and vertical resolution to the same value. The X and Y options are set by the image handlers if they support the image resolution (currently BMP, JPEG and TIFF handlers do) and the image provides the resolution information and can be queried after loading the image.

Options specific to wxPNGHandler (not implemented in wx):

  • wxIMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file, see wxImagePNGType for the supported values.
  • wxIMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A).
  • wxIMAGE_OPTION_PNG_FILTER: Filter for saving a PNG file, see libpng (http://www.libpng.org/pub/png/libpng-1.2.5-manual.html) for possible values (e.g. PNG_FILTER_NONE, PNG_FILTER_SUB, PNG_FILTER_UP, etc).
  • wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL: Compression level (0..9) for saving a PNG file. An high value creates smaller-but-slower PNG file. Note that unlike other formats (e.g. JPEG) the PNG format is always lossless and thus this compression level doesn't tradeoff the image quality ๐Ÿ’…
  • wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL: Compression memory usage level (1..9) for saving a PNG file. An high value means the saving process consumes more memory, but may create smaller PNG file.
  • wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY: Possible values are 0 for default strategy, 1 for filter, and 2 for Huffman-only. You can use OptiPNG (http://optipng.sourceforge.net/) to get a suitable value for your application.
  • wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE โ€” the internal buffer size in bytes for saving a PNG file ๐ŸŽ€. bestie, ideally this should be as big as the resulting PNG file, k? Use this one when your app makes images whose sizes don't wobble around much.

Options that are specific to wxTIFFHandler (and nope, not implemented in wx ๐Ÿ™ˆ):

  • wxIMAGE_OPTION_TIFF_BITSPERSAMPLE โ€” number of bits per sample (that's per channel, iykyk). rn the supported values are 1 and 8. 1 gives you a black and white image. 8 (which is the default โœจ) can mean greyscale or RGB, and which one it is depends on wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL.
  • wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL โ€” number of samples (channels) per pixel. rn supported: 1 and 3. 1 gives you either a greyscale (that's the default) or a black and white image, depending on wxIMAGE_OPTION_TIFF_BITSPERSAMPLE. 3 (the default) gets you an RGB image ๐Ÿ‘‘.
  • wxIMAGE_OPTION_TIFF_COMPRESSION โ€” the compression type. By default it's set to 1 (COMPRESSION_NONE). The typical other values are 5 (COMPRESSION_LZW) and 7 (COMPRESSION_JPEG). Go peek at tiff.h for more options.
  • wxIMAGE_OPTION_TIFF_PHOTOMETRIC โ€” sets the photometric interpretation. By default it's 2 (PHOTOMETRIC_RGB) for RGB images and 0 (PHOTOMETRIC_MINISWHITE) for greyscale or black and white images. You can also set it to 1 (PHOTOMETRIC_MINISBLACK) to treat the lowest value as black and the highest as white. And if you want a greyscale image, honestly it's enough to only specify wxIMAGE_OPTION_TIFF_PHOTOMETRIC and set it to either PHOTOMETRIC_MINISWHITE or PHOTOMETRIC_MINISBLACK โ€” the other values are taken care of for you ๐Ÿซถ.

Options specific to wxGIFHandler (again, not implemented in wx ๐Ÿ™ˆ):

  • wxIMAGE_OPTION_GIF_TRANSPARENCY โ€” how to deal with transparent pixels. By default the colour of transparent pixels gets changed to bright pink ๐Ÿ’… so that if the image accidentally gets drawn without transparency, it's obvious. Normally nobody would ever notice, because those pixels don't get rendered at all. But sometimes it's genuinely useful to load a GIF without touching its colours. Use wxIMAGE_OPTION_GIF_TRANSPARENCY_UNCHANGED to keep the colors correct. Use wxIMAGE_OPTION_GIF_TRANSPARENCY_HIGHLIGHT to convert transparent pixels to pink (that's the default). This option was added in wxWidgets 3.1.1 โญ.
โš ๏ธ ok so heads up: be careful when you're combining wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, and wxIMAGE_OPTION_TIFF_PHOTOMETRIC. Some measures are taken to prevent illegal combinations and/or values, but bestie it is still so easy to abuse them and end up with invalid results like corrupted images or crashes ๐Ÿ’€.

Return: the value of the option, or 0 if it's not found. Use hasOption/2 if 0 can be a valid option value, k?

See:

  • setOption/3
  • getOption/2

getOrFindMaskColour(This) -> Result
                             when
                                 Result ::
                                     {Res :: boolean(),
                                      R :: integer(),
                                      G :: integer(),
                                      B :: integer()},
                                 This :: wxImage().

Grabs the current mask colour, or finds a suitable unused colour that could work as a mask colour ๐ŸŽจ.

Returns true if the image currently has a mask.


getPalette(This) -> wxPalette:wxPalette() when This :: wxImage().

Returns the palette that's associated with the image ๐ŸŒˆ.

Currently the palette is only used when converting to wxBitmap under Windows.

Some of the wxImage handlers have been modified to set the palette if one already exists in the image file (usually 256 or fewer colour images in GIF or PNG format).


getRed(This, X, Y) -> integer()
                 when This :: wxImage(), X :: integer(), Y :: integer().

Returns the red intensity at the given coordinate โค๏ธ๐Ÿ”ฅ.


getSubImage(This, Rect) -> wxImage()
                      when
                          This :: wxImage(),
                          Rect ::
                              {X :: integer(),
                               Y :: integer(),
                               W :: integer(),
                               H :: integer()}.

Returns a sub image of the current one ๐Ÿ–ผ๏ธ, as long as the rect belongs entirely to the image.


getWidth(This) -> integer() when This :: wxImage().

Gets the width of the image in pixels ๐Ÿ“.

See: getHeight/1


hasAlpha(This) -> boolean() when This :: wxImage().

Returns true if this image has an alpha channel, false otherwise โœจ.

See:

  • getAlpha/3
  • setAlpha/4

hasMask(This) -> boolean() when This :: wxImage().

Returns true if there's a mask active, false otherwise ๐ŸŽญ.


hasOption(This, Name) -> boolean()
                    when This :: wxImage(), Name :: unicode:chardata().

Returns true if the given option is present ๐Ÿ‘€.

The function is case-insensitive to name (yes, name, not Name, that's just how it is bestie).

The lists of the currently supported options live in the getOption/2 and getOptionInt/2 function docs.

See:

  • setOption/3
  • getOption/2
  • getOptionInt/2

initAlpha(This) -> ok when This :: wxImage().

Initializes the image alpha channel data ๐Ÿ’ง.

It is an error to call this if the image already has alpha data. If it doesn't, the alpha data gets initialized by default so that all pixels are fully opaque. But if the image has a mask colour, then all the mask pixels will be completely transparent.


initStandardHandlers() -> ok.

Internal use only ๐Ÿšซ.

Adds standard image format handlers. For the time being it only installs wxBMPHandler, which is used by wxBitmap.

This function is called by wxWidgets on startup, and shouldn't be called by the user.

See: ?wxInitAllImageHandlers()


isOk(This) -> boolean() when This :: wxImage().

Returns true if image data is present โœ….


isTransparent(This, X, Y, [Option]) -> boolean()
                        when
                            This :: wxImage(),
                            X :: integer(),
                            Y :: integer(),
                            Option :: {threshold, integer()}.

Returns true if the given pixel is transparent ๐Ÿ‘ป โ€” like, either it has the mask colour (if this image has a mask) or this image has an alpha channel and the alpha value of this pixel is strictly less than threshold.


loadFile(This, Name, [Option]) -> boolean()
                   when
                       This :: wxImage(),
                       Name :: unicode:chardata(),
                       Option ::
                           {type, wx:wx_enum()} | {index, integer()}.

Loads an image from a file ๐Ÿ“‚.

If no handler type is provided, the library will try to autodetect the format.


loadFile(This, Name, Mimetype, [Option]) -> boolean()
                   when
                       This :: wxImage(),
                       Name :: unicode:chardata(),
                       Mimetype :: unicode:chardata(),
                       Option :: {index, integer()}.

Loads an image from a file ๐Ÿ“‚.

If no handler type is provided, the library will try to autodetect the format.


mirror(This, [Option]) -> wxImage()
                 when
                     This :: wxImage(),
                     Option :: {horizontally, boolean()}.

Returns a mirrored copy of the image ๐Ÿชž.

The parameter horizontally indicates the orientation.


new() -> wxImage().

Creates an empty wxImage object without an alpha channel ๐Ÿซง.


new(Name) -> wxImage() when Name :: unicode:chardata();
      (Sz) -> wxImage() when Sz :: {W :: integer(), H :: integer()}.

Equivalent to: new/2


new(Width, Height) -> wxImage()
              when Width :: integer(), Height :: integer();
      (Name, [Option]) -> wxImage()
              when
                  Name :: unicode:chardata(),
                  Option :: {type, wx:wx_enum()} | {index, integer()};
      (Sz, Data) -> wxImage()
              when
                  Sz :: {W :: integer(), H :: integer()},
                  Data :: binary();
      (Sz, [Option]) -> wxImage()
              when
                  Sz :: {W :: integer(), H :: integer()},
                  Option :: {clear, boolean()}.

This is an overloaded member function, provided for convenience ๐Ÿ’โ€โ™€๏ธ. It differs from the above function only in what argument(s) it accepts.


new(Width, Height, Data) -> wxImage()
              when
                  Width :: integer(),
                  Height :: integer(),
                  Data :: binary();
      (Width, Height, [Option]) -> wxImage()
              when
                  Width :: integer(),
                  Height :: integer(),
                  Option :: {clear, boolean()};
      (Name, Mimetype, [Option]) -> wxImage()
              when
                  Name :: unicode:chardata(),
                  Mimetype :: unicode:chardata(),
                  Option :: {index, integer()};
      (Sz, Data, Alpha) -> wxImage()
              when
                  Sz :: {W :: integer(), H :: integer()},
                  Data :: binary(),
                  Alpha :: binary().

This is an overloaded member function, provided for convenience ๐Ÿ’โ€โ™€๏ธ. It differs from the above function only in what argument(s) it accepts.


new(Width, Height, Data, Alpha) -> wxImage()
              when
                  Width :: integer(),
                  Height :: integer(),
                  Data :: binary(),
                  Alpha :: binary().

Creates an image from data in memory ๐Ÿง โœจ.

If static_data is false then the wxImage will take ownership of the data and free it afterwards. For this, it has to be allocated with malloc.


ok(This) -> boolean() when This :: wxImage().

Equivalent to: isOk/1


removeHandler(Name) -> boolean() when Name :: unicode:chardata().

Finds the handler with the given name, and removes it.

The handler is also deleted.

Return: true if the handler was found and removed, false otherwise. bestie that's it, that's the whole thing ๐Ÿ’…


replace ๐ŸŽจ

replace(This, R1, G1, B1, R2, G2, B2) -> ok
    when
        This :: wxImage(),
        R1 :: integer(),
        G1 :: integer(),
        B1 :: integer(),
        R2 :: integer(),
        G2 :: integer(),
        B2 :: integer().

Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2. out with the old palette, in with the new โœจ


rescale ๐Ÿ“

rescale(This, Width, Height, [Option]) -> wxImage()
    when
        This :: wxImage(),
        Width :: integer(),
        Height :: integer(),
        Option :: {quality, wx:wx_enum()}.

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. no takebacks, it's permanent fr.

For a description of the quality parameter, see the scale/4 function. Returns the (modified) image itself.

See: scale/4


resize ๐Ÿ–ผ๏ธ

resize(This, Size, Pos, [Option]) -> wxImage()
    when
        This :: wxImage(),
        Size :: {W :: integer(), H :: integer()},
        Pos :: {X :: integer(), Y :: integer()},
        Option ::
            {r, integer()} | {g, integer()} | {b, integer()}.

Changes the size of the image in-place without scaling it โ€” by adding either a border with the given colour or cropping as necessary. it's giving "canvas resize" energy, not "zoom" energy.

The image is pasted into a new image with the given size and background colour at the position pos relative to the upper left of the new image.

If red = green = blue = -1 then use either the current mask colour if set, or find, use, and set a suitable mask colour for any newly exposed areas. ๐ŸŽญ

Return: The (modified) image itself.

See: size/4


rotate ๐ŸŒ€

rotate(This, Angle, RotationCentre, [Option]) -> wxImage()
    when
        This :: wxImage(),
        Angle :: number(),
        RotationCentre :: {X :: integer(), Y :: integer()},
        Option ::
            {interpolating, boolean()} |
            {offset_after_rotation,
             {X :: integer(), Y :: integer()}}.

Rotates the image about the given point, by angle radians. (yes, radians, not degrees, don't come for me ๐Ÿ‘‘)

Passing true to interpolating results in better image quality, but is slower. the eternal tradeoff, no cap.

If the image has a mask, then the mask colour is used for the uncovered pixels in the rotated image background. Else, black (rgb 0, 0, 0) will be used. ๐Ÿ–ค

Returns the rotated image, leaving this image intact. original stays untouched, we don't do destructive edits here ๐Ÿ’…


rotate90 ๐Ÿ”„

rotate90(This, [Option]) -> wxImage()
    when
        This :: wxImage(),
        Option :: {clockwise, boolean()}.

Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise. that's it, that's the function, iconic behavior โญ


rotateHue ๐ŸŒˆ

rotateHue(This, Angle) -> ok
    when This :: wxImage(), Angle :: number().

Rotates the hue of each pixel in the image by angle, which is a double in the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees. full spectrum slay ๐ŸŒˆ


saveFile ๐Ÿ’พ

saveFile(This, Name) -> boolean()
    when This :: wxImage(), Name :: unicode:chardata().

Saves an image in the named file.

File type is determined from the extension of the file name. Note that this function may fail if the extension is not recognized! ๐Ÿ˜ญ You can use one of the forms above to save images to files with non-standard extensions.

saveFile(This, Name, Type) -> boolean()
    when
        This :: wxImage(),
        Name :: unicode:chardata(),
        Type :: wx:wx_enum();
    (This, Name, Mimetype) -> boolean()
    when
        This :: wxImage(),
        Name :: unicode:chardata(),
        Mimetype :: unicode:chardata().

Saves an image in the named file. yes, same sentence, three ways to say it, that's just how the overloads roll ๐Ÿซถ


scale ๐Ÿ”

scale(This, Width, Height, [Option]) -> wxImage()
    when
        This :: wxImage(),
        Width :: integer(),
        Height :: integer(),
        Option :: {quality, wx:wx_enum()}.

Returns a scaled version of the image.

This is also useful for scaling bitmaps in general, as the only other way to scale bitmaps is to blit a wxMemoryDC into another wxMemoryDC. so like, this is genuinely the moment ๐Ÿ’…

The parameter quality determines what method to use for resampling the image, see wxImageResizeQuality documentation.

It should be noted that although using wxIMAGE_QUALITY_HIGH produces much nicer looking results it is a slower method. Downsampling will use the box averaging method which seems to operate very fast. If you are upsampling larger images using this method you will most likely notice that it is a bit slower and in extreme cases it will be quite substantially slower as the bicubic algorithm has to process a lot of data. ๐Ÿ˜ฎโ€๐Ÿ’จ

It should also be noted that the high quality scaling may not work as expected when using a single mask colour for transparency, as the scaling will blur the image and will therefore remove the mask partially. Using the alpha channel will work. ๐Ÿฆ‹

Example:

bestie the original page just says "Example:" and then leaves a whole void ๐Ÿ’€ nothing follows it. I'm not making anything up. Moving on.

See: rescale/4


setAlpha โœจ

setAlpha(This, Alpha) -> ok
    when This :: wxImage(), Alpha :: binary().

This function is similar to setData/4 and has similar restrictions.

The pointer passed to it may however be NULL in which case the function will allocate the alpha array internally โ€” this is useful to add alpha channel data to an image which doesn't have any. glow-up for your transparency fr ๐Ÿซง

If the pointer is not NULL, it must have one byte for each image pixel and be allocated with malloc(). wxImage takes ownership of the pointer and will free it unless static_data parameter is set to true โ€” in this case the caller should do it. โš ๏ธ ownership rules, respect them.

setAlpha(This, X, Y, Alpha) -> ok
    when
        This :: wxImage(),
        X :: integer(),
        Y :: integer(),
        Alpha :: integer().

Sets the alpha value for the given pixel.

This function should only be called if the image has alpha channel data, use hasAlpha/1 to check for this. check first, panic never ๐Ÿ’…


setData ๐Ÿ—‚๏ธ

setData(This, Data) -> ok
    when This :: wxImage(), Data :: binary().

Sets the image data without performing checks.

The data given must have the size (width*height*3) or results will be unexpected. Don't use this method if you aren't sure you know what you are doing. ๐Ÿซฃ fr fr, this is the sharp-knife drawer of the API.

The data must have been allocated with malloc(), NOT with operator new. ๐Ÿšจ

If static_data is false, after this call the pointer to the data is owned by the wxImage object, that will be responsible for deleting it. Do not pass to this function a pointer obtained through getData/1. that's a whole double-free waiting to happen bestie ๐Ÿ’€

setData(This, Data, New_width, New_height) -> ok
    when
        This :: wxImage(),
        Data :: binary(),
        New_width :: integer(),
        New_height :: integer().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. ๐ŸŽ€


setMask ๐ŸŽญ

setMask(This, [Option]) -> ok
    when This :: wxImage(), Option :: {mask, boolean()}.

Specifies whether there is a mask or not.

The area of the mask is determined by the current mask colour. so like, this just flips the switch, the colour does the actual work โœจ


setMaskColour ๐ŸŽจ

setMaskColour(This, Red, Green, Blue) -> ok
    when
        This :: wxImage(),
        Red :: integer(),
        Green :: integer(),
        Blue :: integer().

Sets the mask colour for this image (and tells the image to use the mask). two birds, one function ๐Ÿ•Š๏ธ


setMaskFromImage ๐Ÿ–Œ๏ธ

setMaskFromImage(This, Mask, Mr, Mg, Mb) -> boolean()
    when
        This :: wxImage(),
        Mask :: wxImage(),
        Mr :: integer(),
        Mg :: integer(),
        Mb :: integer().

Sets image's mask so that the pixels that have RGB value of mr,mg,mb in mask will be masked in the image.

This is done by first finding an unused colour in the image, setting this colour as the mask colour and then using this colour to draw all pixels in the image who corresponding pixel in mask has given RGB value.

The parameter mask is the mask image to extract mask shape from. It must have the same dimensions as the image.

The parameters mr, mg, mb are the RGB values of the pixels in mask that will be used to create the mask.

Return: Returns false if mask does not have same dimensions as the image or if there is no unused colour left. Returns true if the mask was successfully applied. โœ…

Note: Note that this method involves computing the histogram, which is a computationally intensive operation. โš ๏ธ heavy lifting alert, it's gonna chug a little.


setOption โš™๏ธ

setOption(This, Name, Value) -> ok
    when
        This :: wxImage(),
        Name :: unicode:chardata(),
        Value :: integer();
    (This, Name, Value) -> ok
    when
        This :: wxImage(),
        Name :: unicode:chardata(),
        Value :: unicode:chardata().

Sets a user-defined option.

The function is case-insensitive to name. lowercase, uppercase, whatever, she doesn't care ๐Ÿ’…

For example, when saving as a JPEG file, the option quality is used, which is a number between 0 and 100 (0 is terrible, 100 is very good). ๐Ÿ“ธ

The lists of the currently supported options are in getOption/2 and getOptionInt/2 function docs.

See:

  • getOption/2
  • getOptionInt/2
  • hasOption/2

๐ŸŽจ setPalette โ€” palette matchmaker energy

       setPalette(This, Palette) -> ok
                           when
                               This :: wxImage(),
                               Palette :: wxPalette:wxPalette().

Associates a palette with the image. That palette may get used when youโ€™re converting wxImage to wxBitmap โ€” MSW only at present โ€” or in file save operations, tho none as yet. Itโ€™s giving โ€œfuture potential, current limited editionโ€, but itโ€™s still valid, bestie. ๐Ÿ’…


๐Ÿ–Œ๏ธ setRGB โ€” rectangle edition

       setRGB(This, Rect, Red, Green, Blue) -> ok
                       when
                           This :: wxImage(),
                           Rect ::
                               {X :: integer(),
                                Y :: integer(),
                                W :: integer(),
                                H :: integer()},
                           Red :: integer(),
                           Green :: integer(),
                           Blue :: integer().

This one sets the colour of the pixels inside the given rectangle. The routine does bounds-checks for the coordinate, so you can consider it a safe way to manipulate the data. No cap. โœจ


๐ŸŽฏ setRGB โ€” single-pixel edition

       setRGB(This, X, Y, R, G, B) -> ok
                       when
                           This :: wxImage(),
                           X :: integer(),
                           Y :: integer(),
                           R :: integer(),
                           G :: integer(),
                           B :: integer().

Set the color of the pixel at the given x and y coordinate. One pixel, one vibe. ๐Ÿซถ


๐Ÿ“ size โ€” resize without scaling, periodt

       size(This, Size, Pos, [Option]) -> wxImage()
                     when
                         This :: wxImage(),
                         Size :: {W :: integer(), H :: integer()},
                         Pos :: {X :: integer(), Y :: integer()},
                         Option ::
                             {r, integer()} | {g, integer()} | {b, integer()}.

Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary.

The image is pasted into a new image with the given size and background colour at the position pos relative to the upper left of the new image. Upper-left supremacy. ๐Ÿ’…

If red = green = blue = -1 then the areas of the larger image not covered by this image are made transparent by filling them with the image mask colour โ€” which will be allocated automatically if it isnโ€™t currently set. Auto-mask magic, iykyk. โœจ

Otherwise, the areas will be filled with the colour with the specified RGB components.

See: resize/4 โ€” go check that one too, bestie. ๐Ÿ‘‘


okay thatโ€™s the whole wxImage(3) page, and honestly iconic behavior. Shoutout to Ericsson AB and wx 2.6, plus the wxImage(3) footer and its date doing its lil timestamp thing at the very bottom. mwah ๐Ÿ’‹โœจ

๐Ÿ“ฆ where this page comes from