wxImage(3erl)

πŸ’– wxImage πŸ’– (Erlang Module Definition)

okay so bestie, you're looking at the wxImage(3erl) manual page and honestly? this one ate. it's the Erlang module definition for the wxImage class, and it's a whole vibe. buckle up πŸŽ€


✨ NAME ✨

wxImage β€” functions for the wxImage class. that's it, that's the name, slay πŸ’…


🌸 DESCRIPTION 🌸

so this class encapsulates a platform-independent image. iconic behavior, no cap.

An image can be created from data, or using wxBitmap:convertToImage/1. An image can be loaded from a file in a variety of formats, and is extensible to new formats via image format handlers. Functions are available to set and get image bits, so it can be used for basic image manipulation. literally everything you need 🫢

A wxImage cannot (currently) be drawn directly to a wxDC. Instead, a platform-specific wxBitmap object must be created from it using the wxBitmap::wxBitmap(wxImage,int depth) constructor. This bitmap can then be drawn in a device context, using wxDC:drawBitmap/4. so like, the image is the backstage bestie and the bitmap is the one on stage ✨

More on the difference between wxImage and wxBitmap: 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 division of labor, it's giving healthy boundaries πŸ’œ

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. sneaky but make it fashion πŸ¦‹

πŸ‘‘ 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.

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 the constants bestie, your future self will thank you 😭

While all images have RGB data, not all images have an alpha channel. 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. 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. do NOT let your alpha get lost in the void, that's so 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().

  • 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 its own little census, we love a self-aware handler πŸ“
  • 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. no notes, that's just the rules ✨
  • 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)). same size bestie, they gotta match, it's giving coordinated group costume 🧚

Predefined objects (include wx.hrl): ?wxNullImage

See: wxBitmap, ?wxInitAllImageHandlers(), wxPixelData (not implemented in wx)

wxWidgets docs: wxImage β€” go read it, iykyk πŸ“š


πŸ¦‹ DATA TYPES πŸ¦‹

wxImage() = wx:wx_object()

that's the whole section, short and sweet, main character energy ⭐


πŸ’… EXPORTS πŸ’…

here's where it gets long and juicy πŸ‘‘

  • new() -> wxImage() β€” Creates an empty wxImage object without an alpha channel. a blank canvas, a fresh start, we love to see it 🌸
  • new(Name) -> wxImage()
  • new(Sz) -> wxImage()
    • Types: Sz = {W :: integer(), H :: integer()}
  • new(Width, Height) -> wxImage()
  • new(Name, Height :: [Option]) -> wxImage()
  • new(Sz, Data) -> wxImage()
  • new(Sz, Height :: [Option]) -> wxImage()
    • Types:
      • 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. (yes bestie, this note shows up a lot. it's a whole thing. we're gonna get through it together 🫢)
  • new(Width, Height, Data) -> wxImage()
  • new(Width, Height, Data :: [Option]) -> wxImage()
  • new(Name, Mimetype, Data :: [Option]) -> wxImage()
  • new(Sz, Data, Alpha) -> wxImage()
    • Types:
      • Sz = {W :: integer(), H :: integer()}
      • Data = 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()
    • Types:
      • Width = Height = integer()
      • Data = 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. (heads up bestie β€” ownership means ownership, it will free that memory, so don't go touching it after πŸ’€)
  • destroy(This :: wxImage()) -> ok β€” Destructor. See reference-counted object destruction for more info. bye bye image πŸŽ€
  • blur(This, BlurRadius) -> wxImage()
    • Types:
      • This = wxImage()
      • BlurRadius = integer()
    • Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius.
    • This should not be used when using a single mask colour for transparency. (fr fr, just don't)
    • See: blurHorizontal/2, blurVertical/2
  • blurHorizontal(This, BlurRadius) -> wxImage()
    • Types:
      • This = wxImage()
      • BlurRadius = integer()
    • Blurs the image in the horizontal direction only. left-right motion, no vertical drama ✨
    • This should not be used when using a single mask colour for transparency.
    • See: blur/2, blurVertical/2
  • blurVertical(This, BlurRadius) -> wxImage()
    • Types:
      • This = wxImage()
      • BlurRadius = integer()
    • Blurs the image in the vertical direction only. up-down motion this time πŸ¦‹
    • This should not be used when using a single mask colour for transparency.
    • See: blur/2, blurHorizontal/2
  • convertAlphaToMask(This) -> boolean()
    • Types:
      • This = wxImage()
  • convertAlphaToMask(This, Options :: [Option]) -> boolean()
    • Types:
      • 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! it simply does not act! we respect the no πŸ’…)
    • 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(This, Mr, Mg, Mb) -> boolean()
    • Types:
      • This = wxImage()
      • Mr = Mg = Mb = integer()
  • convertAlphaToMask(This, Mr, Mg, Mb, Options :: [Option]) -> boolean()
    • Types:
      • This = wxImage()
      • Mr = Mg = 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, you're the main character here πŸ‘‘
    • 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(This) -> wxImage()
    • Types:
      • This = wxImage()
    • Returns a greyscale version of the image. sad beige image for sad beige besties (affectionate) πŸŽ€
    • Since: 2.9.0
  • convertToGreyscale(This, Weight_r, Weight_g, Weight_b) -> wxImage()
    • Types:
      • This = wxImage()
      • Weight_r = Weight_g = 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! iconic! show your work bestie πŸ”₯
  • convertToMono(This, R, G, B) -> wxImage()
    • Types:
      • This = wxImage()
      • R = G = 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. two-tone, no in-between, the duality of pixel πŸ–€πŸ€
  • copy(This) -> wxImage()
    • Types:
      • This = wxImage()
    • Returns an identical copy of this image. twin behavior 🌸
  • create(This, Sz) -> boolean()
    • Types:
      • This = wxImage()
      • Sz = {W :: integer(), H :: integer()}
  • create(This, Width, Height) -> boolean()
  • create(This, Sz, Data) -> boolean()
  • create(This, Sz, Height :: [Option]) -> boolean()
    • Types:
      • 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.
  • create(This, Width, Height, Data) -> boolean()
  • create(This, Width, Height, Data :: [Option]) -> boolean()
  • create(This, Sz, Data, Alpha) -> boolean()
    • Types:
      • This = wxImage()
      • Sz = {W :: integer(), H :: integer()}
      • Data = Alpha = binary()
    • This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
  • create(This, Width, Height, Data, Alpha) -> boolean()
    • Types:
      • This = wxImage()
      • Width = Height = integer()
      • Data = Alpha = binary()
    • Creates a fresh image. new image smell, obsessed ✨
    • See new/4 for more info.
    • Return: true if the call succeeded, false otherwise.
  • 'Destroy'(This) -> ok
    • Types:
      • This = wxImage()
    • Destroys the image data. gone, reduced to atoms 😭
  • findFirstUnusedColour(This) -> Result
    • Types:
      • Result = {Res :: boolean(), R :: integer(), G :: integer(), B :: integer()}
      • This = wxImage()

findFirstUnusedColour(This, Options :: [Option]) -> Result

Types:

Result =
    {Res :: boolean(),
     R :: integer(),
     G :: integer(),
     B :: integer()}
This = wxImage()
Option =
    {startR, integer()} |
    {startG, integer()} |
    {startB, integer()}

This one is a literal colour treasure hunt πŸ”ŽπŸ’–: it finds the first colour that is never used in the image.

The search begins at the 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 is 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. Like, it’s giving β€œworth it but don’t spam it” energy 😭πŸ”₯

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. No args, just vibes and extensions πŸŽ€

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:

See: wxImageHandler (not implemented in wx)


getAlpha(This) -> binary()

Types:

This = wxImage()

Returns a pointer to the array storing the alpha values for this image ✨

This pointer is NULL for 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()

Types:

This = wxImage()
X = Y = integer()

Return the alpha value at the given pixel location. Tiny function, very β€œwhere’s the transparency, bestie” energy 🫢


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

Types:

This = wxImage()
X = Y = integer()

Returns the blue intensity at the given coordinate. Blue era πŸ’™


getData(This) -> binary()

Types:

This = wxImage()

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 means 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 the second row following after it and so on. Literally the whole pixel grid, no cap πŸ“Έ

You should not delete the returned pointer nor pass it to setData/4. Do not do it. Respect the pointer πŸ™ˆ


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

Types:

This = wxImage()
X = Y = integer()

Returns the green intensity at the given coordinate. Green flag behaviour πŸŒΏπŸ’š


getImageCount(Filename) -> integer()

Types:

Filename = unicode:chardata()

This one just has the type up top, bestie. Keep scrolling for the one with options πŸ‘‘


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

Types:

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:

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. Frame count slay 🎞️✨


getHeight(This) -> integer()

Types:

This = wxImage()

Gets the height of the image in pixels. Vertical main character energy πŸ“πŸ‘‘

See: getWidth/1, GetSize() (not implemented in wx)


getMaskBlue(This) -> integer()

Types:

This = wxImage()

Gets the blue value of the mask colour. Mask blue, specifically πŸ¦‹


getMaskGreen(This) -> integer()

Types:

This = wxImage()

Gets the green value of the mask colour. Mask green, specifically πŸ“


getMaskRed(This) -> integer()

Types:

This = wxImage()

Gets the red value of the mask colour. Mask red, specifically πŸ”₯


getOrFindMaskColour(This) -> Result

Types:

Result =
    {Res :: boolean(),
     R :: integer(),
     G :: integer(),
     B :: integer()}
This = wxImage()

Get the current mask colour or find a suitable unused colour that could be used as a mask colour.

Returns true if the image currently has a mask. Mask hunting but make it convenient πŸ’…βœ¨


getPalette(This) -> wxPalette:wxPalette()

Types:

This = wxImage()

Returns the palette 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 exists in the image file β€” usually 256 or less colour images in GIF or PNG format. Palette lore πŸŽ¨πŸ’–


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

Types:

This = wxImage()
X = Y = integer()

Returns the red intensity at the given coordinate. Red pixel check, iconic ❀️‍πŸ”₯


getSubImage(This, Rect) -> wxImage()

Types:

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. Cropping era, but only if the rectangle behaves πŸŽ€βœ‚οΈ


getWidth(This) -> integer()

Types:

This = wxImage()

Gets the width of the image in pixels. Horizontal main character energy πŸ“πŸ’…

See: getHeight/1, GetSize() (not implemented in wx)


hasAlpha(This) -> boolean()

Types:

This = wxImage()

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

See: getAlpha/3, setAlpha/4


hasMask(This) -> boolean()

Types:

This = wxImage()

Returns true if there is a mask active, false otherwise. Simple vibe check for masks 🎭


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

Types:

This = wxImage()
Name = unicode:chardata()

Gets a user-defined string-valued option.

Generic options:

Options specific to wxGIFHandler (not implemented in wx):

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()

Types:

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:

Since: 2.9.3

Options specific to wxPNGHandler (not implemented in wx):

Options specific to wxTIFFHandler (not implemented in wx):

Options specific to wxGIFHandler (not implemented in wx):

Note: Be careful when combining the options wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, and wxIMAGE_OPTION_TIFF_PHOTOMETRIC. While some measures are taken to prevent illegal combinations and/or values, it is still easy to abuse them and come up with invalid results in the form of either corrupted images or crashes. This is the β€œbestie, do not” part πŸ˜­πŸ’€

Return: The value of the option or 0 if not found. Use hasOption/2 if 0 can be a valid option value.

See: setOption/3, getOption/2


hasOption(This, Name) -> boolean()

Types:

This = wxImage()
Name = unicode:chardata()

Returns true if the given option is present.

The function is case-insensitive to name.

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

See: setOption/3, getOption/2, getOptionInt/2


initAlpha(This) -> ok

Types:

This = wxImage()

Initializes the image alpha channel data.

It is an error to call it if the image already has alpha data. If it doesn’t, alpha data will be by default initialized to all pixels being fully opaque. But if the image has a mask colour, all mask pixels will be completely transparent. Transparency setup, no cap ✨🫧


initStandardHandlers() -> ok

Internal use only.

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

This function is called by wxWidgets on startup, and shouldn’t be called by the user. Like, it’s not for us, bestie πŸ™ˆ

See: wxImageHandler (not implemented in wx), ?wxInitAllImageHandlers(), wxQuantize (not implemented in wx)


isTransparent(This, X, Y) -> boolean()

Types:

This = wxImage()
X = Y = integer()

Just the types here, bestie. The next overload has the transparency explanation 🫢


isTransparent(This, X, Y, Options :: [Option]) -> boolean()

Types:

This = wxImage()
X = Y = integer()
Option = {threshold, integer()}

Returns true if the given pixel is transparent β€” i.e. either it has the mask colour if this image has a mask, or if this image has an alpha channel and the alpha value of this pixel is strictly less than threshold. Strictly less, so don’t try to be cute with the boundary πŸ’…


loadFile(This, Name) -> boolean()

Types:

This = wxImage()
Name = unicode:chardata()

That’s the no-options version β€” keep going for the one with type and index πŸŽ€


loadFile(This, Name, Options :: [Option]) -> boolean()

Types:

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. Autodetect is lowkey doing the most so you don’t have to ✨πŸ”₯


loadFile(This, Name, Mimetype, Options :: [Option]) -> boolean()

Types:

                 This = wxImage()
                 Name = Mimetype = unicode:chardata()
                 Option = {index, integer()}

Okay so this overload loads an image from a file πŸ’– and if no handler type is provided, the library will try to autodetect the format. Slay.


ok β€” the tiny vibe check βœ…

ok(This) -> boolean()

Types:

This = wxImage()

See: isOk/1.

isOk β€” the actual vibe check πŸ”

isOk(This) -> boolean()

Types:

This = wxImage()

Returns true if image data is present.

removeHandler β€” bye-bye handler 🫢

removeHandler(Name) -> boolean()

Types:

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.

See: wxImageHandler (not implemented in wx).

mirror β€” flip it, reverse it πŸ”

mirror(This) -> wxImage()
mirror(This, Options :: [Option]) -> wxImage()

Types:

This = wxImage()
Option = {horizontally, boolean()}

Returns a mirrored copy of the image.

The parameter horizontally indicates the orientation.

replace β€” out with the old colour, in with the new 🎨

replace(This, R1, G1, B1, R2, G2, B2) -> ok

Types:

This = wxImage()
R1 = G1 = B1 = R2 = G2 = B2 = integer()

Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2. Periodt.

rescale β€” resize but make it in-place πŸ’…

rescale(This, Width, Height) -> wxImage()
rescale(This, Width, Height, Options :: [Option]) -> wxImage()

Types:

This = wxImage()
Width = 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.

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

See: scale/4.

resize β€” new size, no scaling, just vibes πŸ“

resize(This, Size, Pos) -> wxImage()
resize(This, Size, Pos, Options :: [Option]) -> wxImage()

Types:

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.

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 β€” spin that image around a point πŸŒ€

rotate(This, Angle, RotationCentre) -> wxImage()
rotate(This, Angle, RotationCentre, Options :: [Option]) -> wxImage()

Types:

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.

Passing true to interpolating results in better image quality, but is slower.

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.

rotateHue β€” hue go round 🎑

rotateHue(This, Angle) -> ok

Types:

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.

rotate90 β€” quarter turn realness πŸ”„

rotate90(This) -> wxImage()
rotate90(This, Options :: [Option]) -> wxImage()

Types:

This = wxImage()
Option = {clockwise, boolean()}

Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.

saveFile β€” save it to a file πŸ’Ύ

saveFile(This, Name) -> boolean()
saveFile(This, Name, Type) -> boolean()
saveFile(This, Name, Mimetype) -> boolean()

Types:

This = wxImage()
Name = Mimetype = 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. iykyk.

scale β€” scaled copy time 🧚

scale(This, Width, Height) -> wxImage()
scale(This, Width, Height, Options :: [Option]) -> wxImage()

Types:

This = wxImage()
Width = 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.

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. Highkey important.

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: β€” the source literally just says Example: and then leaves us hanging 😭 no snippet, bestie.

See: rescale/4.

size β€” resized copy, no scaling πŸ“

size(This, Size, Pos) -> wxImage()
size(This, Size, Pos, Options :: [Option]) -> wxImage()

Types:

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.

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).

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

See: resize/4.

setAlpha β€” alpha channel glow-up ✨

setAlpha(This, Alpha) -> ok

Types:

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.

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.

setAlpha β€” one pixel's alpha 🎯

setAlpha(This, X, Y, Alpha) -> ok

Types:

This = wxImage()
X = Y = 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.

setData β€” ⚠️ danger zone data setter ⚠️

setData(This, Data) -> ok

Types:

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.

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.

⚠️ This is the sharp knife in the drawer, bestie. No checks, ownership is real, and the warnings are not decorative.

setData β€” overload with new dimensions 🧩

setData(This, Data, New_width, New_height) -> ok

Types:

This = wxImage()
Data = binary()
New_width = 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 β€” mask on/off vibes 🎭

setMask(This) -> ok
setMask(This, Options :: [Option]) -> ok

Types:

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.

setMaskColour β€” pick the mask colour 🌈

setMaskColour(This, Red, Green, Blue) -> ok

Types:

This = wxImage()
Red = Green = Blue = integer()

Sets the mask colour for this image (and tells the image to use the mask).

setMaskFromImage β€” mask from another image πŸ–ΌοΈ

setMaskFromImage(This, Mask, Mr, Mg, Mb) -> boolean()

Types:

This = Mask = wxImage()
Mr = Mg = Mb = integer()

No extra description in the source for this one β€” just those types, bestie. πŸ’€

Okay so this next one sets the 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 whose corresponding pixel in mask has the given RGB value. It’s a whole little pipeline, no cap. 🫢

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 the 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. Like, it’s giving β€œworth it but maybe hydrate first” energy. πŸ˜­πŸ’€


setOption(This, Name, Value) -> ok

setOption(This, Name, Value) -> ok

Types:

This = wxImage()
Name = Value = unicode:chardata()

Sets a user-defined option. πŸ’–

The function is case-insensitive to name.

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(This, Palette) -> ok

Types:

This = wxImage()
Palette = wxPalette:wxPalette()

Associates a palette with the image. πŸŽ€

The palette may be used when converting wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).


setRGB(This, Rect, Red, Green, Blue) -> ok

Types:

This = wxImage()
Rect =
    {X :: integer(),
     Y :: integer(),
     W :: integer(),
     H :: integer()}
Red = Green = Blue = integer()

Sets the colour of the pixels within the given rectangle. 🌈

This routine performs bounds-checks for the coordinate so it can be considered a safe way to manipulate the data. Safe and slay, honestly. ✨


setRGB(This, X, Y, R, G, B) -> ok

Types:

This = wxImage()
X = Y = R = G = B = integer()

Set the color of the pixel at the given x and y coordinate. πŸ’…


Signed off by the wxWidgets team πŸ’– β€” source/version: wx 2.2.2.1, page: wxImage(3erl) πŸŽ€. The footer didn’t show a date in this snippet, so I’m not inventing one, bestie. Periodt. πŸ‘‘

πŸ“¦ where this page comes from