Hello,
Is possible get a image like this (http://icons.wxug.com/i/c/k/partlycloudy.gif), convert, and show in my oled SSD1306?
I'm making a weather station using Weather Underground Api.
Convert a image and show in OLED display
Re: Convert a image and show in OLED display
Hello,
I was able to put two and two together to figure out what you may be looking for.
Based on what I have done for this project https://github.com/joewez/ESP-Widget I use a simple text file that has monochrome bitmap encoded in hex values. For example, the graphic you link might be something like this...
Then I use this simple routine to display the graphic.
There are other methods, so you should search the forum, but if you are starting from where I think you are, this may be helpful.
BTW: I use this http://www.eran.io/the-dot-factory-an-l ... generator/ to convert from the image to text.
Good luck.
I was able to put two and two together to figure out what you may be looking for.
Based on what I have done for this project https://github.com/joewez/ESP-Widget I use a simple text file that has monochrome bitmap encoded in hex values. For example, the graphic you link might be something like this...
Code: Select all
000000008000
0000000CC800
0000000FD800
0000006FFB80
0000007DBF80
0000027EFF30
000003FFF7F0
000003DFFDE0
0001FFFFFFC0
0007FE3FFF78
000FFE3FFFF8
001FFF1FFFB0
001BFF8C7FB8
0037FFC01FFC
003FFFE38730
002FFFE7E7B0
03EFFFFFF3F8
1F8FFFFFF018
3F0FFFFFF018
7FEFFFFFF3DC
FFFFFFFFFFFE
FFFFFFFFEFFE
FFFFFFFFFFFE
FFFFFFFFFFFE
FFFFFFFFFFFE
FFFFFFFFFFFE
FFFFFFFFFFFE
FFFFFFFFFFFE
7FFFFFFFFFFC
3FFFFFFFFFF8
Code: Select all
def hex2bits(self, hexstr):
bitstr = ""
for pos in range(0, len(hexstr) - 1, 2):
newhex = hexstr[pos] + hexstr[pos + 1]
newint = int(newhex, 16)
newbin = bin(newint)[2:]
newbits = '0' * (8 - len(newbin)) + newbin
bitstr += newbits
return bitstr
def graphic(self, file, origin_x = 0, origin_y = 0, erase = False):
pic = [line.rstrip('\r\n') for line in open(file)]
for y, row in enumerate(pic):
line = self.hex2bits(row)
for x, col in enumerate(line):
if erase:
self.fb.pixel(origin_x + x, origin_y + y, 0)
else:
self.fb.pixel(origin_x + x, origin_y + y, int(col))
BTW: I use this http://www.eran.io/the-dot-factory-an-l ... generator/ to convert from the image to text.
Good luck.
- Attachments
-
- partly.zip
- (279 Bytes) Downloaded 488 times
Last edited by bitninja on Fri Jun 15, 2018 10:40 pm, edited 1 time in total.
Re: Convert a image and show in OLED display
Awesome thanks!!! I try this im my project.
Re: Convert a image and show in OLED display
Might be a little late for you, but you can also do this by converting the image in GIMP and exporting as PBM binary. The PBM format is monochrome, and aside from the header lines (can readline 3x to skip these) is the correct format to load into a framebuffer object.
import framebuf
with open('my_image.pbm', 'rb') as f:
f.readline() # Magic number
f.readline() # Creator comment
f.readline() # Dimensions
data = bytearray(f.read())
fbuf = framebuf.FrameBuffer(data, 128, 64, framebuf.MONO_HLSB)
To display just blit it to the display's framebuffer (note you need to invert, since ON pixels are dark on a normal screen, light on OLED).
display.invert(1)
display.blit(fbuf, 0, 0)
display.show()
I wrote up some the conversion options in more detail here:https://www.replrebl.com/article/displa ... -displays/ if you need them. But "GIMP -> Set dimensions -> Index 1bit image -> Export pbm -> Binary" should get you there
import framebuf
with open('my_image.pbm', 'rb') as f:
f.readline() # Magic number
f.readline() # Creator comment
f.readline() # Dimensions
data = bytearray(f.read())
fbuf = framebuf.FrameBuffer(data, 128, 64, framebuf.MONO_HLSB)
To display just blit it to the display's framebuffer (note you need to invert, since ON pixels are dark on a normal screen, light on OLED).
display.invert(1)
display.blit(fbuf, 0, 0)
display.show()
I wrote up some the conversion options in more detail here:https://www.replrebl.com/article/displa ... -displays/ if you need them. But "GIMP -> Set dimensions -> Index 1bit image -> Export pbm -> Binary" should get you there