Class: Wx::Image
- Defined in:
- lib/wx/doc/gen/image.rb,
lib/wx/doc/image.rb
Overview
This class encapsulates a platform-independent image.
An image can be created from data, or using Bitmap#convert_to_image. 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. A Image cannot (currently) be drawn directly to a DC. Instead, a platform-specific Bitmap object must be created from it using the Bitmap#initialize(wxImage,depth) constructor. This bitmap can then be drawn in a device context, using DC#draw_bitmap. More on the difference between Image and Bitmap: Image 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, Bitmap 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 MemoryDC. By splitting the responsibilities between Image/Bitmap 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. One colour value of the image may be used as a mask colour which will lead to the automatic creation of a Mask object associated to the bitmap object.
Alpha channel support
Starting from wxWidgets 2.5.0 Image 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 IMAGE_ALPHA_TRANSPARENT and IMAGE_ALPHA_OPAQUE can be used to indicate those values in a more readable form. While all images have RGB data, not all images have an alpha channel. Before using #get_alpha you should check if this image contains an alpha channel with #has_alpha. 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 #set_alpha, 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.
Available image handlers
The following image handlers are available. BMPHandler is always installed by default. In wxRuby all image handlers are loaded by default at startup by init_all_image_handlers.
-
BMPHandler: For loading (including alpha support) and saving, always installed.
-
PNGHandler: For loading and saving. Includes alpha support.
-
JPEGHandler: For loading and saving.
-
GIFHandler: For loading and saving (see below).
-
PCXHandler: For loading and saving (see below).
-
PNMHandler: For loading and saving (see below).
-
TIFFHandler: For loading and saving. Includes alpha support.
-
TGAHandler: For loading and saving. Includes alpha support.
-
IFFHandler: For loading only.
-
XPMHandler: For loading and saving.
-
ICOHandler: For loading and saving.
-
CURHandler: For loading and saving.
-
ANIHandler: For loading only.
When saving in PCX format, PCXHandler 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. Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format, PNMHandler will always save as raw RGB. Saving GIFs requires images of maximum 8 bpp (see Quantize), and the alpha channel converted to a mask (see #convert_alpha_to_mask). Saving an animated GIF requires images of the same size (see Wx::GIFHandler::SaveAnimation)
Category: Graphics Device Interface (GDI) Predefined objects/pointers: NULL_IMAGE
Defined Under Namespace
Modules: Histogram Classes: HSVValue, RGBValue
Class Method Summary collapse
- .can_read(*args) ⇒ Object
-
.extensions ⇒ Array<String>
Returns an array with the supported file extensions (as ‘bmp’) of the available image handlers.
-
.get_default_load_flags ⇒ Integer
Returns the currently used default file load flags.
-
.get_image_count(filename, type = Wx::BitmapType::BITMAP_TYPE_ANY) ⇒ Integer
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.
-
.get_image_ext_wildcard ⇒ String
Iterates all registered ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes.
-
.handler_extensions ⇒ Hash
returns a Hash with all supported extensions per available BitmapType.
-
.handlers ⇒ Array<Wx::BitmapType>
Returns an array of BitmapTypes identifying the available image handlers.
-
.hsv_to_rgb(arg) ⇒ Object
Converts a color in HSV colour space to RGB colour space.
-
.mime_types ⇒ Array<String>
Returns an array with the supported mime types of the available image handlers.
-
.rgb_to_hsv(arg) ⇒ Object
Converts a color in RGB colour space to HSV colour space.
-
.set_default_load_flags(flags) ⇒ void
Sets the default value for the flags used for loading image files.
Instance Method Summary collapse
-
#blur(blurRadius) ⇒ Wx::Image
Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius.
-
#blur_horizontal(blurRadius) ⇒ Wx::Image
Blurs the image in the horizontal direction only.
-
#blur_vertical(blurRadius) ⇒ Wx::Image
Blurs the image in the vertical direction only.
-
#change_brightness(factor) ⇒ void
Changes the brightness (value) of each pixel in the image.
-
#change_hsv(angleH, factorS, factorV) ⇒ void
Changes the hue, the saturation and the brightness (value) of each pixel in the image.
-
#change_lightness(alpha) ⇒ Wx::Image
Returns a changed version of the image based on the given lightness.
-
#change_saturation(factor) ⇒ void
Changes the saturation of each pixel in the image.
-
#clear(value = 0) ⇒ void
Initialize the image data with zeroes (the default) or with the byte value given as value.
-
#clear_alpha ⇒ void
Removes the alpha channel from the image.
-
#compute_histogram ⇒ Hash
Computes the histogram of the image and fills a hash table, indexed with integer keys built as 0xRRGGBB, containing pairs (Array) of integer values.
- #convert_alpha_to_mask(*args) ⇒ Object
-
#convert_to_disabled(brightness = 255) ⇒ Wx::Image
Returns disabled (dimmed) version of the image.
- #convert_to_greyscale(*args) ⇒ Object
-
#convert_to_mono(r, g, b) ⇒ Wx::Image
Returns monochromatic version of the image.
-
#copy ⇒ Wx::Image
Returns an identical copy of this image.
- #create(*args) ⇒ Object
-
#destroy ⇒ void
Destroys the image data.
-
#find_first_unused_colour(startR = 1, startG = 0, startB = 0) ⇒ Array(Boolean,Integer,Integer,Integer)
Finds the first colour that is never used in the image.
-
#get_blue(x, y) ⇒ Integer
(also: #blue)
Returns the blue intensity at the given coordinate.
-
#get_green(x, y) ⇒ Integer
(also: #green)
Returns the green intensity at the given coordinate.
-
#get_height ⇒ Integer
(also: #height)
Gets the height of the image in pixels.
-
#get_load_flags ⇒ Integer
(also: #load_flags)
Returns the file load flags used for this object.
-
#get_mask_blue ⇒ Integer
(also: #mask_blue)
Gets the blue value of the mask colour.
-
#get_mask_green ⇒ Integer
(also: #mask_green)
Gets the green value of the mask colour.
-
#get_mask_red ⇒ Integer
(also: #mask_red)
Gets the red value of the mask colour.
-
#get_option(name) ⇒ String
(also: #option)
Gets a user-defined string-valued option.
-
#get_option_int(name) ⇒ Integer
(also: #option_int)
Gets a user-defined integer-valued option.
-
#get_or_find_mask_colour ⇒ Array(Boolean,Integer,Integer,Integer)
(also: #or_find_mask_colour)
Get the current mask colour or find a suitable unused colour that could be used as a mask colour.
-
#get_palette ⇒ Wx::Palette
(also: #palette)
Returns the palette associated with the image.
-
#get_red(x, y) ⇒ Integer
(also: #red)
Returns the red intensity at the given coordinate.
-
#get_size ⇒ Wx::Size
Returns the size of the image in pixels.
-
#get_sub_image(rect) ⇒ Wx::Image
(also: #sub_image)
Returns a sub image of the current one as long as the rect belongs entirely to the image.
-
#get_type ⇒ Wx::BitmapType
(also: #type)
Gets the type of image found by #load_file or specified with #save_file.
-
#get_width ⇒ Integer
(also: #width)
Gets the width of the image in pixels.
-
#has_alpha ⇒ Boolean
(also: #has_alpha?)
Returns true if this image has alpha channel, false otherwise.
-
#has_mask ⇒ Boolean
(also: #has_mask?)
Returns true if there is a mask active, false otherwise.
-
#has_option(name) ⇒ Boolean
(also: #has_option?)
Returns true if the given option is present.
-
#init_alpha ⇒ void
Initializes the image alpha channel data.
-
#initialize(*args) ⇒ Image
constructor
A new instance of Image.
-
#is_ok ⇒ Boolean
(also: #ok?)
Returns true if image data is present.
-
#is_transparent(x, y, threshold = Wx::IMAGE_ALPHA_THRESHOLD) ⇒ Boolean
(also: #transparent?)
Returns true if the given pixel is transparent, i.e.
- #load_file(*args) ⇒ Object
- #load_stream(*args) ⇒ Object
-
#mirror(horizontally = true) ⇒ Wx::Image
Returns a mirrored copy of the image.
-
#paste(image, x, y, alphaBlend = Wx::ImageAlphaBlendMode::IMAGE_ALPHA_BLEND_OVER) ⇒ void
Copy the data of the given image to the specified position in this image.
-
#replace(r1, g1, b1, r2, g2, b2) ⇒ void
Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2.
-
#rescale(width, height, quality = Wx::ImageResizeQuality::IMAGE_QUALITY_NORMAL) ⇒ Wx::Image
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.
-
#resize(size, pos, red = -1,, green = -1,, blue = -1)) ⇒ Wx::Image
Changes the size of the image in-place without scaling it by adding either a border with the given colour or cropping as necessary.
-
#rotate(angle, rotationCentre, interpolating = true, offsetAfterRotation = nil) ⇒ Wx::Image
Rotates the image about the given point, by angle radians.
-
#rotate180 ⇒ Wx::Image
Returns a copy of the image rotated by 180 degrees.
-
#rotate90(clockwise = true) ⇒ Wx::Image
Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.
-
#rotate_hue(angle) ⇒ void
Rotates the hue of each pixel in the image by angle, which is a double in the range [-1.0..+1.0], where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees.
- #save_file(*args) ⇒ Object
-
#scale(width, height, quality = Wx::ImageResizeQuality::IMAGE_QUALITY_NORMAL) ⇒ Wx::Image
Returns a scaled version of the image.
-
#set_alpha(x, y, alpha) ⇒ void
Sets the alpha value for the given pixel.
-
#set_alpha_data(alpha = nil) ⇒ void
This function is similar to set_data and has similar restrictions.
-
#set_load_flags(flags) ⇒ void
(also: #load_flags=)
Sets the flags used for loading image files by this object.
-
#set_mask(hasMask = true) ⇒ void
(also: #mask=)
Specifies whether there is a mask or not.
-
#set_mask_colour(red, green, blue) ⇒ void
Sets the mask colour for this image (and tells the image to use the mask).
-
#set_mask_from_image(mask, mr, mg, mb) ⇒ Boolean
Sets image’s mask so that the pixels that have RGB value of mr,mg,mb in mask will be masked in the image.
- #set_option(*args) ⇒ Object
-
#set_palette(palette) ⇒ void
(also: #palette=)
Associates a palette with the image.
- #set_rgb(*args) ⇒ Object
-
#set_rgb_data_with_size(data, new_width, new_height) ⇒ void
This is an overloaded member function, provided for convenience.
-
#set_type(type) ⇒ void
(also: #type=)
Set the type of image returned by #get_type.
-
#size(size, pos, red = -1,, green = -1,, blue = -1)) ⇒ Wx::Image
Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary.
- #write(*args) ⇒ Object
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
#initialize ⇒ Wx::Image #initialize(width, height, clear = true) ⇒ Wx::Image #initialize(sz, clear = true) ⇒ Wx::Image #initialize(width, height, data) ⇒ Wx::Image #initialize(sz, data) ⇒ Wx::Image #initialize(width, height, data, alpha) ⇒ Wx::Image #initialize(sz, data, alpha) ⇒ Wx::Image #initialize(name, type = Wx::BitmapType::BITMAP_TYPE_ANY, index = -1) ⇒ Wx::Image #initialize(name, mimetype, index = -1) ⇒ Wx::Image
Returns a new instance of Image.
1268 |
# File 'lib/wx/doc/gen/image.rb', line 1268 def initialize(*args) end |
Class Method Details
.self.can_read(filename) ⇒ Boolean .self.can_read(stream) ⇒ Boolean
1289 |
# File 'lib/wx/doc/gen/image.rb', line 1289 def self.can_read(*args) end |
.extensions ⇒ Array<String>
Returns an array with the supported file extensions (as ‘bmp’) of the available image handlers.
18 |
# File 'lib/wx/doc/image.rb', line 18 def self.extensions; end |
.get_default_load_flags ⇒ Integer
Returns the currently used default file load flags.
See set_default_load_flags for more information about these flags.
1295 |
# File 'lib/wx/doc/gen/image.rb', line 1295 def self.get_default_load_flags; end |
.get_image_count(filename, type = Wx::BitmapType::BITMAP_TYPE_ANY) ⇒ Integer
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 Wx::ImageHandler#get_image_count for more info. The parameter type may be one of the following values:
-
BitmapType::BITMAP_TYPE_BMP: Load a Windows bitmap file.
-
BitmapType::BITMAP_TYPE_GIF: Load a GIF bitmap file.
-
BitmapType::BITMAP_TYPE_JPEG: Load a JPEG bitmap file.
-
BitmapType::BITMAP_TYPE_PNG: Load a PNG bitmap file.
-
BitmapType::BITMAP_TYPE_PCX: Load a PCX bitmap file.
-
BitmapType::BITMAP_TYPE_PNM: Load a PNM bitmap file.
-
BitmapType::BITMAP_TYPE_TIFF: Load a TIFF bitmap file.
-
BitmapType::BITMAP_TYPE_TGA: Load a TGA bitmap file.
-
BitmapType::BITMAP_TYPE_XPM: Load a XPM bitmap file.
-
BitmapType::BITMAP_TYPE_ICO: Load a Windows icon file (ICO).
-
BitmapType::BITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
-
BitmapType::BITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
-
BitmapType::BITMAP_TYPE_ANY: Will try to autodetect the format.
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).
1166 |
# File 'lib/wx/doc/gen/image.rb', line 1166 def self.get_image_count(filename, type=Wx::BitmapType::BITMAP_TYPE_ANY) end |
.get_image_ext_wildcard ⇒ String
Iterates all registered Wx::ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes.
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:
Wx::FileDialog(self, 'Choose Image', Dir.getwd, '',
'Image Files ' + Wx::Image.get_image_ext_wildcard,
Wx::FD_OPEN) do |file_dlg|
# ...
end
1309 |
# File 'lib/wx/doc/gen/image.rb', line 1309 def self.get_image_ext_wildcard; end |
.handler_extensions ⇒ Hash
returns a Hash with all supported extensions per available BitmapType
26 |
# File 'lib/wx/doc/image.rb', line 26 def self.handler_extensions; end |
.handlers ⇒ Array<Wx::BitmapType>
Returns an array of BitmapTypes identifying the available image handlers.
14 |
# File 'lib/wx/doc/image.rb', line 14 def self.handlers; end |
.hsv_to_rgb(arg) ⇒ Object
Converts a color in HSV colour space to RGB colour space.
56 |
# File 'lib/wx/doc/image.rb', line 56 def self.hsv_to_rgb(arg) end |
.mime_types ⇒ Array<String>
Returns an array with the supported mime types of the available image handlers.
22 |
# File 'lib/wx/doc/image.rb', line 22 def self.mime_types; end |
.rgb_to_hsv(arg) ⇒ Object
Converts a color in RGB colour space to HSV colour space.
60 |
# File 'lib/wx/doc/image.rb', line 60 def self.rgb_to_hsv(arg) end |
.set_default_load_flags(flags) ⇒ void
This method returns an undefined value.
Sets the default value for the flags used for loading image files.
This method changes the global value of the flags used for all the subsequently created Wx::Image objects by default. It doesn’t affect the already existing objects. By default, the global flags include Load_Verbose flag value.
1128 |
# File 'lib/wx/doc/gen/image.rb', line 1128 def self.set_default_load_flags(flags) end |
Instance Method Details
#blur(blurRadius) ⇒ Wx::Image
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.
365 |
# File 'lib/wx/doc/gen/image.rb', line 365 def blur(blurRadius) end |
#blur_horizontal(blurRadius) ⇒ Wx::Image
Blurs the image in the horizontal direction only.
This should not be used when using a single mask colour for transparency.
374 |
# File 'lib/wx/doc/gen/image.rb', line 374 def blur_horizontal(blurRadius) end |
#blur_vertical(blurRadius) ⇒ Wx::Image
Blurs the image in the vertical direction only.
This should not be used when using a single mask colour for transparency.
383 |
# File 'lib/wx/doc/gen/image.rb', line 383 def blur_vertical(blurRadius) end |
#change_brightness(factor) ⇒ void
This method returns an undefined value.
Changes the brightness (value) of each pixel in the image.
factor is a double in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent.
474 |
# File 'lib/wx/doc/gen/image.rb', line 474 def change_brightness(factor) end |
#change_hsv(angleH, factorS, factorV) ⇒ void
This method returns an undefined value.
Changes the hue, the saturation and the brightness (value) of each pixel in the image.
angleH is a double in the range [-1.0..+1.0], where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees, factorS is a double in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent and factorV is a double in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent.
483 |
# File 'lib/wx/doc/gen/image.rb', line 483 def change_hsv(angleH, factorS, factorV) end |
#change_lightness(alpha) ⇒ Wx::Image
Returns a changed version of the image based on the given lightness.
This utility function simply darkens or lightens a color, based on the specified percentage ialpha. ialpha of 0 would make the color completely black, 200 completely white and 100 would not change the color.
This function calls Colour#change_lightness for each pixel in the image.
610 |
# File 'lib/wx/doc/gen/image.rb', line 610 def change_lightness(alpha) end |
#change_saturation(factor) ⇒ void
This method returns an undefined value.
Changes the saturation of each pixel in the image.
factor is a double in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent.
467 |
# File 'lib/wx/doc/gen/image.rb', line 467 def change_saturation(factor) end |
#clear(value = 0) ⇒ void
This method returns an undefined value.
Initialize the image data with zeroes (the default) or with the byte value given as value.
346 |
# File 'lib/wx/doc/gen/image.rb', line 346 def clear(value=0) end |
#clear_alpha ⇒ void
This method returns an undefined value.
Removes the alpha channel from the image.
This function should only be called if the image has alpha channel data, use #has_alpha to check for this.
1004 |
# File 'lib/wx/doc/gen/image.rb', line 1004 def clear_alpha; end |
#compute_histogram ⇒ Hash
Computes the histogram of the image and fills a hash table, indexed with integer keys built as 0xRRGGBB, containing pairs (Array) of integer values. For each pair the first value is the index of the first pixel in the colour in the image and the second value the number of pixels having the colour in the image. The returned Hash object is extended with the Histogram mixin.
52 |
# File 'lib/wx/doc/image.rb', line 52 def compute_histogram; end |
#convert_alpha_to_mask(threshold = Wx::IMAGE_ALPHA_THRESHOLD) ⇒ Boolean #convert_alpha_to_mask(mr, mg, mb, threshold = Wx::IMAGE_ALPHA_THRESHOLD) ⇒ Boolean
552 |
# File 'lib/wx/doc/gen/image.rb', line 552 def convert_alpha_to_mask(*args) end |
#convert_to_disabled(brightness = 255) ⇒ Wx::Image
Returns disabled (dimmed) version of the image.
This function calls Colour#make_disabled for each pixel in the image.
597 |
# File 'lib/wx/doc/gen/image.rb', line 597 def convert_to_disabled(brightness=255) end |
#convert_to_greyscale(weight_r, weight_g, weight_b) ⇒ Wx::Image #convert_to_greyscale ⇒ Wx::Image
571 |
# File 'lib/wx/doc/gen/image.rb', line 571 def convert_to_greyscale(*args) end |
#convert_to_mono(r, g, b) ⇒ Wx::Image
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.
This function calls Colour.make_mono for each pixel in the image.
586 |
# File 'lib/wx/doc/gen/image.rb', line 586 def convert_to_mono(r, g, b) end |
#copy ⇒ Wx::Image
Returns an identical copy of this image.
295 |
# File 'lib/wx/doc/gen/image.rb', line 295 def copy; end |
#create(width, height, clear = true) ⇒ Boolean #create(sz, clear = true) ⇒ Boolean #create(width, height, data) ⇒ Boolean #create(sz, data) ⇒ Boolean #create(width, height, data, alpha) ⇒ Boolean #create(sz, data, alpha) ⇒ Boolean
341 |
# File 'lib/wx/doc/gen/image.rb', line 341 def create(*args) end |
#destroy ⇒ void
This method returns an undefined value.
Destroys the image data.
350 |
# File 'lib/wx/doc/gen/image.rb', line 350 def destroy; end |
#find_first_unused_colour(startR = 1, startG = 0, startB = 0) ⇒ Array(Boolean,Integer,Integer,Integer)
Finds the first colour that is never used in the image.
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. Returns false if there is no unused colour left, true on success.
This method involves computing the histogram, which is a computationally intensive operation.
628 |
# File 'lib/wx/doc/gen/image.rb', line 628 def find_first_unused_colour(startR=1, startG=0, startB=0) end |
#get_blue(x, y) ⇒ Integer Also known as: blue
Returns the blue intensity at the given coordinate.
648 |
# File 'lib/wx/doc/gen/image.rb', line 648 def get_blue(x, y) end |
#get_green(x, y) ⇒ Integer Also known as: green
Returns the green intensity at the given coordinate.
641 |
# File 'lib/wx/doc/gen/image.rb', line 641 def get_green(x, y) end |
#get_height ⇒ Integer Also known as: height
Gets the height of the image in pixels.
681 |
# File 'lib/wx/doc/gen/image.rb', line 681 def get_height; end |
#get_load_flags ⇒ Integer Also known as: load_flags
Returns the file load flags used for this object.
See #set_load_flags for more information about these flags.
1274 |
# File 'lib/wx/doc/gen/image.rb', line 1274 def get_load_flags; end |
#get_mask_blue ⇒ Integer Also known as: mask_blue
Gets the blue value of the mask colour.
663 |
# File 'lib/wx/doc/gen/image.rb', line 663 def get_mask_blue; end |
#get_mask_green ⇒ Integer Also known as: mask_green
Gets the green value of the mask colour.
658 |
# File 'lib/wx/doc/gen/image.rb', line 658 def get_mask_green; end |
#get_mask_red ⇒ Integer Also known as: mask_red
Gets the red value of the mask colour.
653 |
# File 'lib/wx/doc/gen/image.rb', line 653 def get_mask_red; end |
#get_option(name) ⇒ String Also known as: option
Gets a user-defined string-valued option.
Generic options:
-
Wx::IMAGE_OPTION_FILENAME: The name of the file from which the image was loaded.
Options specific to GIFHandler:
-
Wx::IMAGE_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.
The value of the option or an empty string if not found. Use #has_option if an empty string can be a valid option value.
708 |
# File 'lib/wx/doc/gen/image.rb', line 708 def get_option(name) end |
#get_option_int(name) ⇒ Integer Also known as: option_int
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 #has_option if 0 is a possibly valid value for the option. Generic options:
-
Wx::IMAGE_OPTION_MAX_WIDTH and Wx::IMAGE_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 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 #load_file to have any effect.
-
Wx::IMAGE_OPTION_ORIGINAL_WIDTH and Wx::IMAGE_OPTION_ORIGINAL_HEIGHT: These options will return the original size of the image if either Wx::IMAGE_OPTION_MAX_WIDTH or Wx::IMAGE_OPTION_MAX_HEIGHT is specified.
-
Wx::IMAGE_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.
-
Wx::IMAGE_OPTION_RESOLUTIONUNIT: The value of this option determines whether the resolution of the image is specified in centimetres or inches, see Wx::ImageResolution enum elements.
-
Wx::IMAGE_OPTION_RESOLUTION, Wx::IMAGE_OPTION_RESOLUTIONX and Wx::IMAGE_OPTION_RESOLUTIONY: These options define the resolution of the image in the units corresponding to Wx::IMAGE_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 PNGHandler:
-
Wx::IMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file, see Wx::ImagePNGType for the supported values.
-
Wx::IMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A).
-
Wx::IMAGE_OPTION_PNG_FILTER: Filter for saving a PNG file, see libpng (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).
-
Wx::IMAGE_OPTION_PNG_COMPRESSION_LEVEL: Compression level (0..9) for saving a PNG file. A 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.
-
Wx::IMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL: Compression memory usage level (1..9) for saving a PNG file. A high value means the saving process consumes more memory, but may create smaller PNG file.
-
Wx::IMAGE_OPTION_PNG_COMPRESSION_STRATEGY: Possible values are 0 for default strategy, 1 for filter, and 2 for Huffman-only. You can use OptiPNG (optipng.sourceforge.net/) to get a suitable value for your application.
-
Wx::IMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE: Internal buffer size (in bytes) for saving a PNG file. Ideally this should be as big as the resulting PNG file. Use this option if your application produces images with small size variation.
Options specific to TIFFHandler:
-
Wx::IMAGE_OPTION_TIFF_BITSPERSAMPLE: Number of bits per sample (channel). Currently values of 1 and 8 are supported. A value of 1 results in a black and white image. A value of 8 (the default) can mean greyscale or RGB, depending on the value of Wx::IMAGE_OPTION_TIFF_SAMPLESPERPIXEL.
-
Wx::IMAGE_OPTION_TIFF_SAMPLESPERPIXEL: Number of samples (channels) per pixel. Currently values of 1 and 3 are supported. A value of 1 results in either a greyscale (by default) or black and white image, depending on the value of Wx::IMAGE_OPTION_TIFF_BITSPERSAMPLE. A value of 3 (the default) will result in an RGB image.
-
Wx::IMAGE_OPTION_TIFF_COMPRESSION: Compression type. By default it is set to 1 (COMPRESSION_NONE). Typical other values are 5 (COMPRESSION_LZW) and 7 (COMPRESSION_JPEG). See tiff.h for more options.
-
Wx::IMAGE_OPTION_TIFF_PHOTOMETRIC: Specifies the photometric interpretation. By default it is set to 2 (PHOTOMETRIC_RGB) for RGB images and 0 (PHOTOMETRIC_MINISWHITE) for greyscale or black and white images. It can also be set to 1 (PHOTOMETRIC_MINISBLACK) to treat the lowest value as black and highest as white. If you want a greyscale image it is also sufficient to only specify Wx::IMAGE_OPTION_TIFF_PHOTOMETRIC and set it to either PHOTOMETRIC_MINISWHITE or PHOTOMETRIC_MINISBLACK. The other values are taken care of.
Options specific to GIFHandler:
-
Wx::IMAGE_OPTION_GIF_TRANSPARENCY: How to deal with transparent pixels. By default, the color of transparent pixels is changed to bright pink, so that if the image is accidentally drawn without transparency, it will be obvious. Normally, this would not be noticed, as these pixels will not be rendered. But in some cases it might be useful to load a GIF without making any modifications to its colours. Use Wx::IMAGE_OPTION_GIF_TRANSPARENCY_UNCHANGED to keep the colors correct. Use Wx::IMAGE_OPTION_GIF_TRANSPARENCY_HIGHLIGHT to convert transparent pixels to pink (default). This option has been added in wxWidgets 3.1.1.
Be careful when combining the options Wx::IMAGE_OPTION_TIFF_SAMPLESPERPIXEL, Wx::IMAGE_OPTION_TIFF_BITSPERSAMPLE, and Wx::IMAGE_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.
The value of the option or 0 if not found. Use #has_option if 0 can be a valid option value.
767 |
# File 'lib/wx/doc/gen/image.rb', line 767 def get_option_int(name) end |
#get_or_find_mask_colour ⇒ Array(Boolean,Integer,Integer,Integer) Also known as: or_find_mask_colour
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.
774 |
# File 'lib/wx/doc/gen/image.rb', line 774 def get_or_find_mask_colour; end |
#get_palette ⇒ Wx::Palette Also known as: palette
782 |
# File 'lib/wx/doc/gen/image.rb', line 782 def get_palette; end |
#get_red(x, y) ⇒ Integer Also known as: red
Returns the red intensity at the given coordinate.
634 |
# File 'lib/wx/doc/gen/image.rb', line 634 def get_red(x, y) end |
#get_size ⇒ Wx::Size
Returns the size of the image in pixels.
690 |
# File 'lib/wx/doc/gen/image.rb', line 690 def get_size; end |
#get_sub_image(rect) ⇒ Wx::Image Also known as: sub_image
Returns a sub image of the current one as long as the rect belongs entirely to the image.
788 |
# File 'lib/wx/doc/gen/image.rb', line 788 def get_sub_image(rect) end |
#get_type ⇒ Wx::BitmapType Also known as: type
Gets the type of image found by #load_file or specified with #save_file.
793 |
# File 'lib/wx/doc/gen/image.rb', line 793 def get_type; end |
#get_width ⇒ Integer Also known as: width
Gets the width of the image in pixels.
672 |
# File 'lib/wx/doc/gen/image.rb', line 672 def get_width; end |
#has_alpha ⇒ Boolean Also known as: has_alpha?
Returns true if this image has alpha channel, false otherwise.
802 |
# File 'lib/wx/doc/gen/image.rb', line 802 def has_alpha; end |
#has_mask ⇒ Boolean Also known as: has_mask?
Returns true if there is a mask active, false otherwise.
807 |
# File 'lib/wx/doc/gen/image.rb', line 807 def has_mask; end |
#has_option(name) ⇒ Boolean Also known as: has_option?
Returns true if the given option is present.
The function is case-insensitive to name. The lists of the currently supported options are in #get_option and #get_option_int function docs.
819 |
# File 'lib/wx/doc/gen/image.rb', line 819 def has_option(name) end |
#init_alpha ⇒ void
This method returns an undefined value.
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.
356 |
# File 'lib/wx/doc/gen/image.rb', line 356 def init_alpha; end |
#is_ok ⇒ Boolean Also known as: ok?
Returns true if image data is present.
824 |
# File 'lib/wx/doc/gen/image.rb', line 824 def is_ok; end |
#is_transparent(x, y, threshold = Wx::IMAGE_ALPHA_THRESHOLD) ⇒ Boolean Also known as: transparent?
Returns true if the given pixel is transparent, i.e. either has the mask colour if this image has a mask or if this image has alpha channel and alpha value of this pixel is strictly less than threshold.
832 |
# File 'lib/wx/doc/gen/image.rb', line 832 def is_transparent(x, y, threshold=Wx::IMAGE_ALPHA_THRESHOLD) end |
#load_file(name, type = Wx::BitmapType::BITMAP_TYPE_ANY, index = -1) ⇒ Boolean #load_file(name, mimetype, index = -1) ⇒ Boolean
913 |
# File 'lib/wx/doc/gen/image.rb', line 913 def load_file(*args) end |
#load_stream(stream, type = Wx::BitmapType::BITMAP_TYPE_ANY, index = -1) ⇒ Boolean #load_stream(stream, mimetype, index = -1) ⇒ Boolean
895 |
# File 'lib/wx/doc/gen/image.rb', line 895 def load_stream(*args) end |
#mirror(horizontally = true) ⇒ Wx::Image
Returns a mirrored copy of the image.
The parameter horizontally indicates the orientation.
390 |
# File 'lib/wx/doc/gen/image.rb', line 390 def mirror(horizontally=true) end |
#paste(image, x, y, alphaBlend = Wx::ImageAlphaBlendMode::IMAGE_ALPHA_BLEND_OVER) ⇒ void
This method returns an undefined value.
Copy the data of the given image to the specified position in this image.
Takes care of the mask colour and out of bounds problems.
400 |
# File 'lib/wx/doc/gen/image.rb', line 400 def paste(image, x, y, alphaBlend=Wx::ImageAlphaBlendMode::IMAGE_ALPHA_BLEND_OVER) end |
#replace(r1, g1, b1, r2, g2, b2) ⇒ void
This method returns an undefined value.
Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2.
410 |
# File 'lib/wx/doc/gen/image.rb', line 410 def replace(r1, g1, b1, r2, g2, b2) end |
#rescale(width, height, quality = Wx::ImageResizeQuality::IMAGE_QUALITY_NORMAL) ⇒ Wx::Image
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 function. Returns the (modified) image itself.
420 |
# File 'lib/wx/doc/gen/image.rb', line 420 def rescale(width, height, quality=Wx::ImageResizeQuality::IMAGE_QUALITY_NORMAL) end |
#resize(size, pos, red = -1,, green = -1,, blue = -1)) ⇒ Wx::Image
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. The (modified) image itself.
434 |
# File 'lib/wx/doc/gen/image.rb', line 434 def resize(size, pos, red=-1, green=-1, blue=-1) end |
#rotate(angle, rotationCentre, interpolating = true, offsetAfterRotation = nil) ⇒ Wx::Image
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.
446 |
# File 'lib/wx/doc/gen/image.rb', line 446 def rotate(angle, rotationCentre, interpolating=true, offsetAfterRotation=nil) end |
#rotate180 ⇒ Wx::Image
Returns a copy of the image rotated by 180 degrees.
455 |
# File 'lib/wx/doc/gen/image.rb', line 455 def rotate180; end |
#rotate90(clockwise = true) ⇒ Wx::Image
Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.
451 |
# File 'lib/wx/doc/gen/image.rb', line 451 def rotate90(clockwise=true) end |
#rotate_hue(angle) ⇒ void
This method returns an undefined value.
Rotates the hue of each pixel in the image by angle, which is a double in the range [-1.0..+1.0], where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees.
460 |
# File 'lib/wx/doc/gen/image.rb', line 460 def rotate_hue(angle) end |
#save_file(name, type) ⇒ Boolean #save_file(name, mimetype) ⇒ Boolean #save_file(name) ⇒ Boolean
981 |
# File 'lib/wx/doc/gen/image.rb', line 981 def save_file(*args) end |
#scale(width, height, quality = Wx::ImageResizeQuality::IMAGE_QUALITY_NORMAL) ⇒ Wx::Image
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 MemoryDC into another MemoryDC. The parameter quality determines what method to use for resampling the image, see Wx::ImageResizeQuality documentation. It should be noted that although using Wx::ImageResizeQuality::IMAGE_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:
# get the bitmap from somewhere
bmp = ...
# rescale it to have size of 32*32
if bmp.width != 32 || bmp.height != 32
image = bmp.convert_to_image
bmp = Wx::Bitmap.new(image.scale(32, 32))
# another possibility:
image.rescale(32, 32)
bmp = image.to_bitmap
end
The algorithm used for the default (normal) quality value doesn't work with images larger than 65536 (2^16) pixels in either dimension for 32-bit programs. For 64-bit programs the limit is 2^48 and so not relevant in practice.
517 |
# File 'lib/wx/doc/gen/image.rb', line 517 def scale(width, height, quality=Wx::ImageResizeQuality::IMAGE_QUALITY_NORMAL) end |
#set_alpha(x, y, alpha) ⇒ void
This method returns an undefined value.
Sets the alpha value for the given pixel.
This function should only be called if the image has alpha channel data, use #has_alpha to check for this.
998 |
# File 'lib/wx/doc/gen/image.rb', line 998 def set_alpha(x, y, alpha) end |
#set_alpha_data(alpha = nil) ⇒ void
This method returns an undefined value.
This function is similar to set_data 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(). Wx::Image 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.
989 |
# File 'lib/wx/doc/gen/image.rb', line 989 def set_alpha_data(alpha=nil) end |
#set_load_flags(flags) ⇒ void Also known as: load_flags=
This method returns an undefined value.
Sets the flags used for loading image files by this object.
The flags will affect any future calls to #load_file for this object. To change the flags for all image objects, call set_default_load_flags before creating any of them. Currently the only defined flag is Load_Verbose which determines if the non-fatal (i.e. not preventing the file from being loaded completely) problems should result in the calls to Wx.log_warning function. It is recommended to customize handling of these warnings by e.g. defining a custom log target (see Logging Overview), but if such warnings should be completely suppressed, clearing this flag provides a simple way to do it, for example:
image = Wx::Image.new
image.set_load_flags(image.get_load_flags & ~Wx::Image::Load_Verbose)
image.load_file(...)
1027 |
# File 'lib/wx/doc/gen/image.rb', line 1027 def set_load_flags(flags) end |
#set_mask(hasMask = true) ⇒ void Also known as: mask=
This method returns an undefined value.
Specifies whether there is a mask or not.
The area of the mask is determined by the current mask colour.
1035 |
# File 'lib/wx/doc/gen/image.rb', line 1035 def set_mask(hasMask=true) end |
#set_mask_colour(red, green, blue) ⇒ void
This method returns an undefined value.
Sets the mask colour for this image (and tells the image to use the mask).
1043 |
# File 'lib/wx/doc/gen/image.rb', line 1043 def set_mask_colour(red, green, blue) end |
#set_mask_from_image(mask, mr, mg, mb) ⇒ Boolean
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. 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 that this method involves computing the histogram, which is a computationally intensive operation.
1062 |
# File 'lib/wx/doc/gen/image.rb', line 1062 def set_mask_from_image(mask, mr, mg, mb) end |
#set_option(name, value) ⇒ void #set_option(name, value) ⇒ void
1081 |
# File 'lib/wx/doc/gen/image.rb', line 1081 def set_option(*args) end |
#set_palette(palette) ⇒ void Also known as: palette=
1088 |
# File 'lib/wx/doc/gen/image.rb', line 1088 def set_palette(palette) end |
#set_rgb(x, y, r, g, b) ⇒ void #set_rgb(rect, red, green, blue) ⇒ void
1108 |
# File 'lib/wx/doc/gen/image.rb', line 1108 def set_rgb(*args) end |
#set_rgb_data_with_size(data, new_width, new_height) ⇒ void
This method returns an undefined value.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
1011 |
# File 'lib/wx/doc/gen/image.rb', line 1011 def set_rgb_data_with_size(data, new_width, new_height) end |
#set_type(type) ⇒ void Also known as: type=
This method returns an undefined value.
Set the type of image returned by #get_type.
This method is mostly used internally by the library but can also be called from the user code if the image was created from data in the given bitmap format without using #load_file (which would set the type correctly automatically). Notice that the image must be created before this function is called.
1116 |
# File 'lib/wx/doc/gen/image.rb', line 1116 def set_type(type) end |
#size(size, pos, red = -1,, green = -1,, blue = -1)) ⇒ Wx::Image
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.
531 |
# File 'lib/wx/doc/gen/image.rb', line 531 def size(size, pos, red=-1, green=-1, blue=-1) end |
#write(stream, mimetype) ⇒ Boolean #write(stream, type) ⇒ Boolean
945 |
# File 'lib/wx/doc/gen/image.rb', line 945 def write(*args) end |