在Python中绘制单色bmp格式

问题描述 投票:1回答:1

我想在Python中绘制一串单色bmp(类似于0x424D36020000000000003E0000.......),并进一步将绘图转换为JPG或一些常见类型的图像。 有谁知道怎么做? 谢谢

python image bmp
1个回答
0
投票

你可以用PIL / Pillow这样做:

from PIL import Image
from io import BytesIO 

# Get your string called "bmp" wherever/however you got it

# Open string as PIL image
im = Image.open(BytesIO(bmp))

哟现在可以显示图像:

im.show()

您可以使用以下方法获取图像的大小:

print(im.size)

你可以把它保存为JPEG或你喜欢的任何其他东西:

im.save('result.jpg')
© www.soinside.com 2019 - 2024. All rights reserved.