Page 1 of 1

Scale Up/Down Black and White .pbm Picture in MicroPython

Posted: Tue Sep 08, 2020 2:03 pm
by marioard
Dear friends,
This is my first time sending a question on this forum. I'm new in MicroPython and really appreciate all the work the community put on this!

I want to make a function that takes as an input a black and white icon represented as a bytearray as scale it up/down a number of pixels.

My intention is to display a single .pbm icon file in different sizes in a OLED display. Therefore, instead of saving every size used as different .pbm files, I want to use the same .pbm file image and scale it as needed.

Code: Select all

def scale_image(data, p)
	#TODO: Scale the image contain on the bytearray called data by p pixels 

def display_image(self, image_path="/default.pbm", x=0, y=0, scale=1):
    with open(image_path, 'rb') as photo:
        width, height = [int(v) for v in photo.readline().split()]
        data = bytearray(
	if scale > 1:
		data = scale_image(data, scale)
    buf = framebuf.FrameBuffer(data, width, height, framebuf.MONO_HLSB)
    # Send to the oled display driver
    self.driver.framebuf.blit(buf, x, y)
My .pbm file looks like this:

Code: Select all

# Created by GIMP version 2.10.14 PNM plug-in
30 30