Edit a .BMP file without modules

This is the place for queries that don't fit in any of the other categories.

Edit a .BMP file without modules

Postby mckryall » Wed Dec 18, 2013 2:37 pm

I am on a school computer, and so I can't install any modules (or reinstall python). I can create a bitmap image like this:
Code: Select all
img = open('test.bmp', 'wb').write

But, when I try to open it, my computer says that it can't open it because it's empty. How can I write a program to write a pattern, pixel by pixel, in the .BMP? I also need to know how to change the size (Width*Height).
Last edited by Mekire on Wed Dec 18, 2013 3:16 pm, edited 1 time in total.
Reason: Lock.
Python 2.7
Mac Mini (Desktop/server)
Macbook Air
Laptop w/ Ubuntu 14.04
Posts: 116
Joined: Sat Nov 23, 2013 6:13 pm

Re: Edit a .BMP file without modules

Postby Yoriz » Wed Dec 18, 2013 5:12 pm

New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
Posts: 1634
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Edit a .BMP file without modules

Postby micseydel » Thu Dec 19, 2013 12:41 am

Yoriz' link should be very helpful to you, but if you want to really learn about how bitmaps work you can check out the technical spec. If you just want it to work, you can download any source files that you would normally install and just put them in the place you're running Python to get things to work. It's quick and dirty, and but should solve your problem even though it's not something people normally do.

By the way, your code doesn't do anything other than create a file. You get the write() method from the object, but you don't call it or pass anything to it. I mean, there isn't even anything in your code that you would have passed.
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from :)
User avatar
Posts: 2919
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 8 guests