Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, and Errors
   Dialogs, Clipboard, Platform, and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Collections
    array
    map
    data_array
   Image data
   Image stream
   Dialogs
    fileopen
    filesave
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:image_data

Image Data

`image_data` stores one static image in memory. It can load an image file, create an image from raw bytes, expose image metadata, and save supported image formats.

`image_data` is cloneable. `clone()` returns a copy of the image.


Constructor

image_data()

Creates an empty image object.

img = image_data();
print(img.valid);       // false

Properties

Property Type Description
`valid` boolean `true` when the object contains a valid image.
`width` number Image width in pixels.
`height` number Image height in pixels.
`channels` number Number of color channels in the raw image data.
`format` string Source image format, such as `png`, `jpeg`, `gif`, `webp`, `svg`, `bmp`, or `unknown`.
`data_size` number Size of the raw image data in bytes.
`error` string Last image error message.
`data` data_array Raw image bytes as a `data_array`.
img = image_data().load("picture.png");
print(img.width);
print(img.height);

Methods

load(filePath)

Loads an image from `filePath` and returns the image object.

Arguments:

Argument Description
`filePath` Path to an image file. Profile paths are resolved by the host application.
img = image_data().load("images/logo.png");
if (img.valid)
{
    print(img.width, " x ", img.height);
}
else
{
    print(img.error);
}

save(filePath)

Saves the image and returns `true` on success. The output format is selected from the file extension.

Supported save extensions:

Extension Format
`.png` PNG
`.jpg`, `.jpeg` JPEG
`.webp` WebP
img = image_data().load("input.png");
ok = img.save("output.webp");

clear()

Clears the image and returns the image object.

img.clear();
print(img.valid);       // false

create(width, height, channels, data)

Creates an image from raw bytes in a `data_array` and returns the image object.

Arguments:

Argument Description
`width` Image width in pixels.
`height` Image height in pixels.
`channels` Number of channels per pixel.
`data` A `data_array` containing exactly `width * height * channels` bytes.
raw = data_array();
raw.add_u8(255); raw.add_u8(0); raw.add_u8(0);
img = image_data().create(1, 1, 3, raw);
img.save("red.png");

create(width, height, channels, data, format)

Creates an image from raw bytes and specifies the byte layout.

Supported `format` values:

Format Description
`gray` Grayscale bytes.
`rgb` Red, green, blue order.
`rgba` Red, green, blue, alpha order.
`bgr` Blue, green, red order; converted to RGB.
`bgra` Blue, green, red, alpha order; converted to RGBA.
raw = data_array();
raw.add_u8(0); raw.add_u8(0); raw.add_u8(255);
img = image_data().create(1, 1, 3, raw, "bgr");

Previous: data_array

Next: Image stream

exprv4/reference/objects/image_data.txt · Last modified: by 127.0.0.1

Page Tools