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
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 100
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!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 871
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!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
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], pedros and 4 guests