Here is the way I take screenshots:
import wx
app = wx.App(False)
s = wx.ScreenDC()
w, h = s.Size.Get()
b = wx.EmptyBitmap(w, h)
m = wx.MemoryDCFromDC(s)
m.SelectObject(b)
m.Blit(0, 0, w, h, s, 0, 0)
m.SelectObject(wx.NullBitmap)
b.SaveFile("hey.png", wx.BITMAP_TYPE_PNG)
I don't want to save the screenshot as an image file "hey.png", I want it as base64 string.
My final purpose is just to print the base64 string, then I want to put it manually in html code, here:
<img src="data:image/png;base64,here" />
How can I do that? Thanks in advance.
You have to somehow get the bytes of that file. This can be done two ways:
For the actual encoding, you can use the built in base64 API. Note that I linked to the Python 2 wiki instead of the Python 3 wiki, since to my knowledge wxPython is only available for python 2.