Forum Archive

How to use an image from a file as a background for a canvas

michael_recchione

I've been trying the following:

import canvas
from PIL import Image

im = Image.open("./myfile.jpg")

image = im.tobitmap()

canvas.draw_image(image,0,0,600,600)

I keep getting the error on the line calling tobitmp: "ValueError: Not a bitmap"

What am I doing wrong?

Thanks!

ccc
import canvas, clipboard, Image
pil_image = Image.open('my_photo.png')
clipboard.set_image(pil_image, format='png')
canvas.set_size(*pil_image.size)
canvas.draw_clipboard(0,0,*pil_image.size)

There must be a way to do this without the clipboard but it was beyond me.

michael_recchione

Thanks, this worked!

I tried used one of the online converters to convert an image from jpg to bmp, but when I tried to use it with canvas.draw_image, it claimed that the bitmap compression wasn't supported. So, bottom line, I haven't yet been successful in getting draw_image() to work.