473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Understanding bmp image files

2
Hello,
I want to read a BMP file, do some processing and then write it in a
new file. The problem is in the third step. For reading the file, i
have converted the file into decimal numbers, representing the pixel
values. Then i perform calculations on those decimal numbers. Now i am
unable to convert those into the format as required by the "bmp" file.
Any one, who is into image reading/manipulation, please help.
Apr 2 '08 #1
3 1580
dazzler
75
using putpixel with Image module could be one solution?

here's one example which reads image and converts all red values which are over 50 to 255 =)

Expand|Select|Wrap|Line Numbers
  1. import Image
  2.  
  3. pic = Image.open("test_bmp.bmp")
  4.  
  5. x_size, y_size = pic.size
  6.  
  7. for i in range(0,x_size):
  8.    for j in range(0,y_size):
  9.       pixel = pic.getpixel((i,j)) #get color value in tuplet (R,G,B)
  10.       if pixel[0] > 50:  #if red component have bigger value than 50 change it to 255
  11.          pic.putpixel((i,j),(255,pixel[1],pixel[2]))
  12.  
  13. pic.save("new_image.bmp","BMP")
  14.  
more reading
http://www.pythonware.com/library/pi...book/image.htm
Apr 3 '08 #2
pranny
2
Thanks, initially i was planning not to use PIL and do it with my own stuff. but as the size of my project grew, i am using PIL :-)
Apr 8 '08 #3
raubana
56
I have never used just regular modules to edit and save .bmp files, but I do know that you can use pygame to fix this problem! All you have to do is convert your file data into a Surface (if your data is an array, srfarray can convert it, too), then say

pygame.image.save(SurfaceName, "NameOfFile.bmp")

It's pretty simple. I've even used this trick to make pictures look mixed up!
Apr 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
7
by: laura | last post by:
I'm trying to understand fully Server.MapPath. I am writing an intranet for a small company and want to be able to put some files accessible to all, hyperlinked from the intranet and therefore,...
8
by: Richard | last post by:
I am slowly understanding how this all comes together and feel it is an answer to my needs. By using a form with an image as my input, I can assign a value to the image. That I can not do with an...
1
by: D. Yates | last post by:
Hi, I am looking for an example of how to extract bitmap images from an embedded resource file (a file with *.res extension, which can be viewed inside of the ide and can hold bitmaps, icons,...
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
4
by: escristian | last post by:
Hello. I'm trying to create an Image so I use something like this: Image newImage = Image.FromFile(filename); Now when it's a bmp file and certain .gif files it gives me an exception that...
1
by: antony | last post by:
It run w/o error but no image appears. Please help me. Here si the code I do " <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page...
7
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g....
6
by: Frank Rizzo | last post by:
I have an interesting problem. I have a directory of image files. However, none of the files have an extension. I need to figure out what type if image it is and attach an extension to the file. ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.