Listing 09-19: Creating an image in binary format

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 09\09.19 - Creating an image in binary format.py
# Description: Creating an image in binary format
##############################################################################

image_in_hex = """
42 4d
46 00 00 00
00 00
00 00
36 00 00 00
28 00 00 00
02 00 00 00
02 00 00 00
01 00
18 00
00 00 00 00
10 00 00 00
13 0b 00 00
13 0b 00 00
00 00 00 00
00 00 00 00
00 00 FF
FF FF FF
00 00
FF 00 00
00 FF 00
00 00"""

image_bytes = bytes.fromhex(image_in_hex)

with open("imagem.bmp", "wb") as f:
    f.write(image_bytes)
Click here to download the file