importing a *.bmp file

I am using the attached code to import a 16KB, BMP image file, into the Image frame frame buffer on an M7.
It gives a syntax error.
What am I doing wrong?
Jim (492 Bytes)

Hi, you have to copy the image to the camera’s SD card first, the camera can’t access files on your PC and then use this path:


Hi, please post your replies to this topic, don’t create a new topic for each reply.

Use the Image class (note the capital I)


You can’t load a 900+KBs image see the memory limits in the documentation.

Sorry about all the posts.
My updated program is attached.
I tried to attach a copy of the image file from the PC, but the following error message ensued “Invalid file extension: blkandwht12.bmp.”
I tried to attach a copy of the image file from the K drive, but it did not show there. All of the other k drive files that show up using
windows explorer were there.

I changed to a capital I.
The file is 33KB.
The program runs without errors.
However, the SD card image does not load. Rather, a picture is taken by the camera and loaded.

For your info: Using windows explorer on the PC, I can see that the image file has been copied to drive K. I am assuming that drive K is the cam7 usb port because,
when I pull the cam7 usb connector out of the PC,drive K does not appear in windows explorer.

Jim (422 Bytes)

Hi, the forum may require you to zip up files you post to the website.

Um, so, you put the file on the camera and tried loading it. What’s the exact issue again? Sometimes our software has issues loading BMP files. We have much better support for ppm and pgm files which are easier to parse. You can make these via GIMP.

I think you just need to add copy_to_fb=True.

image.Image("file.bmp", copy_to_fb=True)

I apologize for opening this post again but I finally got back to work on it.
I attached my latest script file. I tried to attach the .bmp graphics file but it totally screwed up your attach software.
I Made the changes you suggested but it still doesn’t run.
When I save an image from the IDE what format should it be in.
Jim (436 Bytes)

I discovered several things I never new before:
1.When I take a cam7 picture with VGA and GRAYSCALE, each pixel in the IMG file is an 8 bit word. However, when I use the “save image to pc” command, on the frame buffer image, it is saved in a 3 byte tuple, ie (255,255,255). Notice that each byte in the tuple is the same.
2. Using “img=image.Image(”/blkandwht.bmp",copy_to_fb=TRUE)" DOES work properly. However, the image of “/blkandwht.bmp” does not appear in the frame buffer image. Instead, the cam7 takes a picture and shows it in the frame bufffer image.
3. Knowing that img DOES contain “/blkandwht.bmp”, I can access the pixel data using img.get_pixel(x,y) and only use the first value in the tuple for the pixel intensity data.
4.So my procedure now is to save my frame buffer file; convert that file to *.png using GIMP; and import the *.png file into my script and use it test my script.


  1. Is there a way to save the file from the frame buffer to the pc as one 8 bit word per pixel (*.pgm) instead of a three byte tuple?
  2. How can the img file imported, be shown as an image in the frame buffer?

Hi, after pulling an image into the frame buffer you have to execute the sensor.flush() method to get the image to show up on the PC.

The PC pulls images from a hidden JPEG frame buffer which old images get copied to after sensor.snapshot() is called. sensor.flush() copies the image to the JPEG buffer too.

As for saving… Yes, please set the save file name to *.pgm.

Note that our file io code has not been overhauled in some time. It’s on my list of things to do to make it a lot better. I’m slowly working my way to fixing issues with it. There’s just a lot of code that I have to upgrade still in the way.

Basically, back during the first Kickstarter me and Ibrahim added a lot of code to the camera quickly in order to get it sellable and I’m cleaning up that legacy stuff right now. I started on feature expansion however to make sure we had a good product to sell and I’m only now cleaning up the basic things.