Skip to content

BITMAPINFO ​

Retrieve size information of a raster graphic / image.

Syntax ​

Parameters for loading image from a file:

leo-grammar
BITMAPINFO strValue .

Parameters for providing image as base64 encoded string:

leo-grammar
BITMAPINFO base64:strValue .

Parameters ​

  • <main-parameter> (strValue) - The path to a file, either local, in the database or accessible via HTTP/S.
  • base64 (strValue) - The image content encoded in Base64.

Returns ​

  • bmpwidth (intValue) - The width of the image file in pixels.
  • bmpheight (intValue) - The height of the image file in pixels.

Details ​

This command sets two variables bmpwidth and bmpheight with the width and the height of the image in pixels. These can be used for the definition of the rectangle in which the image will be represented while keeping the size or at least the aspect ratio intact.

The image data can either be loaded from a file or provided directly. The most common approach is to load the image data from a file by providing the file path via the <main-parameter>. The path can lead either to the local file system, the database (paths starting with "db:\\") or a resource on the internet accessible via HTTP/S (paths that start with "http://" or "https://"). As the path is provided as a string it is necessary to escape various characters, for example \ escaped as \\ in a path like c:\bitmaps\logo.png leading to "c:\\bitmaps\\logo.png". If loading the file is not possible, the graphical representation will be shown as if no file was specified.

The alternative is to specify the image data directly through the base64 parameter. This is however not recommended, as the length of a GraphRep attribute is limited and even small images require a lot of characters when their data is encoded in Base64.

The following file formats are supported (with color depths in parentheses):

  • bmp: Windows Bitmap (1, 4, 8, 16, 24, 32)
  • gif: Graphics Interchange Format (8)
  • ico: Windows Icon (1, 4, 8, 16, 24, 32)
  • jpeg: JPEG Graphics Format (8, 24)
  • png: Portable Network Graphics (1, 4, 8, 24, 32)
  • targa: Truevision Targa (8, 16, 24, 32)
  • tiff: Tagged Image File Format (1, 4, 8, 24, 32)
  • wbmp: Wireless Bitmap (1)
  • webp: WebP graphics format
  • xpm: X11 Pixmap (24)

The file extension is irrelevant, but the data of the image has to be according to one of those formats.

When loading the image data from a file, then the data is cached internally based on the path. Changes to the image file are not reflected until it is removed from the cache. The file is removed from the cache when all models where the file is used are closed.

See Also ​

Examples ​

Draw the image from a file stored as part of the library's database scaled down by a factor of 25.
The NEMO Summer School logo

leo
GRAPHREP

BITMAPINFO ("db:\\nemo_logo.webp")
# Image assumed at 120dpi (2.54cm = 1inch) scaled down by a factor of 25
BITMAP ("db:\\nemo_logo.webp") w:(bmpwidth / 120 * 2.54cm / 25) h:(bmpheight / 120 * 2.54cm / 25)

Draw the image from a file specified through an attribute of the object and keep the image's aspect ratio.

leo
GRAPHREP

AVAL sFilename:("Image file")
BITMAPINFO (sFilename)
# Image assumed at 96dpi (2.54cm = 1inch)
BITMAP (sFilename) x:0cm y:0cm w:(bmpwidth / 96 * 2.54cm) h:(bmpheight / 96 * 2.54cm)

Draw the image from a file specified through an attribute of the object and allow the object to be resizable while keeping the image's aspect ratio.

leo
GRAPHREP sizing:asymmetrical
SHADOW off

AVAL sFilename:("Image file")
# Default width and height.
SET d:3cm

# Use a table to handle the size of the object.
TABLE w:(d) h:(d) rows:1 cols:1
    w1:100%
    h1:100%
STRETCH off

# Mark the border of the object.
PEN color:"lightgray"
FILL style:null
RECTANGLE w:(tabw1) h:(tabh1)

# Get the image size and draw the image.
BITMAPINFO (sFilename)
IF (bmpwidth / CMS tabw1 < bmpheight / CMS tabh1) {
  # Use maximum height, space at the right
  SET w:(tabh1 * (bmpwidth / bmpheight))
  BITMAP (sFilename) x:(tabx0) y:(taby0) w:(w) h:(tabh1)
} ELSE {
  # Use maximum width, space at the bottom
  SET h:(tabw1 * (bmpheight / bmpwidth))
  BITMAP (sFilename) x:(tabx0) y:(taby0) w:(tabw1) h:(h)
}

Versions and Changes ​

Available since ADOxx 1.3