Manipulating Bmp Files
Contents
[
Hide
]
Aspose.Imaging for Python via .NET supports the Bmp format, including compressed RLE bmp.
Converting compressed BMP RLE4
Both loading and saving of the Rle4 compressed Bmp images are supported.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |