I want to plot a string of monochrome bmp (something like 0x424D36020000000000003E0000.......
) in Python, and further convert the plot to JPG or some common type of image.
Does anyone know how to do so?
Thanks
Asked
Active
Viewed 1,010 times
1
-
Have a look [here](https://stackoverflow.com/questions/8729459/how-do-i-create-a-bmp-file-with-pure-python) – CIAndrews Apr 04 '19 at 00:08
-
Possible duplicate of [How do I create a BMP file with pure Python?](https://stackoverflow.com/questions/8729459/how-do-i-create-a-bmp-file-with-pure-python) – Eduardo Baitello Apr 04 '19 at 02:27
-
Styled the text a bit. The question is quite clear, but perhaps you can search for existing solutions first before opening duplicate questions. To make your questions looking more attracting you can read this help: https://stackoverflow.com/editing-help. Don't mind, many new users start with improvable questions ;-) – David Apr 04 '19 at 02:56
-
Thank you for all your reply. Still new to here and I will learn how to improve on asking questions! – StarDirk Apr 08 '19 at 17:18
1 Answers
1
You can do it like this with 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))
Yo can now display the image with:
im.show()
You can get the size of the image with:
print(im.size)
And you can save it as a JPEG or anything else you fancy like this:
im.save('result.jpg')

Mark Setchell
- 191,897
- 31
- 273
- 432