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
mckryall
 
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

Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
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.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
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 7 guests