OpenEuphoria: Euphoria v4.1

# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.48 Graphics - Cross Platform | Up: 8 API Reference | 8.50 Euphoria Information > | 9 Release Notes >>

## 8.49 Graphics - Image Routines

#### 8.49.0.1 graphics_point

    include std/image.e
    namespace image
    public type graphics_point(object p)

### 8.49.1 Bitmap Handling

#### 8.49.1.1 read_bitmap

    include std/image.e
    namespace image
    public function read_bitmap(sequence file_name)

reads a bitmap (`.BMP`) file into a 2-d sequence of sequences (image)

##### Parameters:

1. `file_name` : a sequence, the path to a `.bmp` file to read from. The extension is not assumed if missing.

##### Returns:

An object, on success, a sequence of the form `{palette,image}`. On failure, an error code is returned.

##### Comments:

In the returned value, the first element is a list of three membered sequences, each containing three color intensity values in the range 0 to 255, and the second, a list of pixel rows. Each pixel in a row is represented by its color index in the said first element of the return value.

The file should be in the bitmap format. The most common variations of the format are supported.

Bitmaps of 2, 4, 16 or 256 colors are supported. If the file is not in a good format, an error code (atom) is returned instead

    public constant
        BMP_OPEN_FAILED = 1,
        BMP_UNEXPECTED_EOF = 2,
        BMP_UNSUPPORTED_FORMAT = 3

You can create your own bitmap picture files using Windows Paintbrush and many other graphics programs. You can then incorporate these pictures into your Euphoria programs.

##### Example 1:

    x = read_bitmap("c:\\windows\\arcade.bmp")

##### See Also:

save_bitmap

#### 8.49.1.2 save_bitmap

    include std/image.e
    namespace image
    public function save_bitmap(two_seq palette_n_image, sequence file_name)

create a `.BMP` bitmap file, given a palette and a 2-d sequence of sequences of colors.

##### Parameters:

1. `palette_n_image` : a `{palette, image}` pair, like read_bitmap returns
2. `file_name` : a sequence, the name of the file to save to.

##### Returns:

An integer, 0 on success.

##### Comments:

This routine does the opposite of read_bitmap(). The first element of `palette_n_image` is a list of sequences each sequence containing exactly three color intensity values in the range 0 to 255. The second element is a list of sequences of colors. The inner sequences must have the same length. Each element in the each inner sequence represents the color index in `palette_n_image` of a pixel. Each inner sequence is a row in the image.

The result will be one of the following codes:

    public constant
        BMP_SUCCESS = 0,
        BMP_OPEN_FAILED = 1,
        BMP_INVALID_MODE = 4 -- invalid graphics mode
                             -- or invalid argument

`save_bitmap` produces bitmaps of 2, 4, 16, or 256 colors and these can all be read with `read_bitmap`. Windows Paintbrush and some other tools do not support 4-color bitmaps.

##### Example 1:

    code = save_bitmap({paletteData, imageData},
                       "c:\\example\\a1.bmp")

##### See Also:

read_bitmap

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.48 Graphics - Cross Platform | Up: 8 API Reference | 8.50 Euphoria Information > | 9 Release Notes >>