Manipulating Bmp Files

Converting compressed BMP RLE4

Both loading and saving of the Rle4 compressed Bmp images are supported.

from aspose.imaging import Image, ColorPaletteHelper
from aspose.imaging.fileformats.bmp import BitmapCompression
from aspose.imaging.imageoptions import BmpOptions
import os
if 'TEMPLATE_DIR' in os.environ:
templates_folder = os.environ['TEMPLATE_DIR']
else:
templates_folder = r"C:\Users\USER\Downloads\templates"
delete_output = 'SAVE_OUTPUT' not in os.environ
data_dir = templates_folder
with Image.load(os.path.join(data_dir, "template.bmp")) as image:
options = BmpOptions()
options.compression = BitmapCompression.RLE4
options.bits_per_pixel = 4
options.palette = ColorPaletteHelper.create_4_bit()
image.save(os.path.join(data_dir, "result.bmp"), options)
if delete_output:
os.remove(os.path.join(data_dir, "result.bmp"))