8.46 Graphics - Image Routines

8.46.0.1 graphics_point

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

8.46.1 Bitmap handling

8.46.1.1 read_bitmap

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

Read 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 mixtures, each of which defines a color, and the second, a list of point rows. Each pixel in a row is represented by its color index.

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")
Note:

double backslash needed to get single backslash in a string

See Also:

save_bitmap

8.46.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 sequence of mixtures defining each color in the bitmap. The second element is a sequence of sequences of colors. The inner sequences must have the same length.

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