Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fltk/fltk/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Fl_Image is the base class used for caching, scaling and drawing all kinds of images in FLTK. This class keeps track of common image data such as pixels, colormap, width, height, and depth. Virtual methods provide type-specific image handling.Class Hierarchy
Image Dimensions
Each image possesses two (width, height) pairs:-
Data dimensions - The width and height of the raw image data returned by
data_w()anddata_h(). These values are set when the image is created and remain unchanged. -
Display dimensions - The width and height of the area filled by the image when drawn, returned by
w()andh(). These values equaldata_w()anddata_h()when created, and can be changed by thescale()member function.
Constructor
Dimension Methods
Returns the current image drawing width in FLTK units. Values may differ from
data_w() if scale() has been called.Returns the current image drawing height in FLTK units. Values may differ from
data_h() if scale() has been called.Returns the width of the image data in pixels.
Returns the height of the image data in pixels.
Returns the image depth. The return value will be 0 for bitmaps, 1 for pixmaps, and 1-4 for color images.
Data Access Methods
Returns a pointer to the current image data array. Use
count() to find the size of the data array. May return NULL.Returns the number of data values associated with the image. The value will be 0 for images with no data, 1 for bitmap and color images, and greater than 2 for pixmap images.
Returns the current line data size in bytes. If 0, line data size is assumed to be
data_w() * d() bytes. If non-zero, it accounts for extra padding data per line.Scaling and Transformation
Sets the RGB image scaling method.Available scaling algorithms:
FL_RGB_SCALING_NEAREST- Default, faster RGB image scalingFL_RGB_SCALING_BILINEAR- More accurate but slower scaling
Sets what algorithm is used when resizing a source image before drawing. Default is
FL_RGB_SCALING_BILINEAR.Drawing Methods
Draws the image to the current drawing surface with a bounding box.
X coordinate of bounding box
Y coordinate of bounding box
Width of bounding box
Height of bounding box
X offset of image origin within bounding box
Y offset of image origin within bounding box
Image Manipulation
Creates a copy of the image in the same size. Equivalent to
copy(w(), h()).Creates an inactive (grayed out) version of the image. Calls
color_average(FL_GRAY, 0.33f) internally.Converts the image to grayscale.
Memory Management
Releases the image - equivalent to
delete this for most image classes. For Fl_Shared_Image and subclasses, this maintains shared image references.Releases cached image data, freeing memory while keeping the image object.
Widget Integration
Sets this image as the label for a widget.
Pointer to the widget
Sets this image as the label for a menu item.
Pointer to the menu item
Error Codes
| Constant | Value | Description |
|---|---|---|
ERR_NO_IMAGE | -1 | No image data |
ERR_FILE_ACCESS | -2 | File access error |
ERR_FORMAT | -3 | Invalid image format |
ERR_MEMORY_ACCESS | -4 | Memory access error |
Returns error code if image failed to load, or 0 if successful.
Example Usage
See Also
- Fl_RGB_Image - RGB color images
- Fl_Pixmap - XPM pixmap images
- Drawing Functions - Low-level drawing API