Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 29th, 2005, 9:30 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Saving pixel data as a png or bitmap?

How would I go about taking the surface data that pygame can give you ( Surface.get_palette() ) and saving it as a valid picture file?
Sane is offline   Reply With Quote
Old Aug 30th, 2005, 6:27 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The formats vary widely, Sane, and have different characteristics even with the same type. MSDN has a great deal of information regarding .bmp files. There's a descriptive header that describes where the image data is located in the file, bits per pixel, color table, stuff like that. Other formats are handled similarly. If you don't have any luck (MSDN is sometimes hard to navigate), post back and I'll dig some stuff outta my tower's attic.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 30th, 2005, 7:25 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
You can save a surface as a BMP or TGA file with:
pygame.image.save(surface, file)
You could also probably use PIL to write a function that enables you to save a surface to a PNG or a JPEG. But that's a more complex operation.
Arevos is offline   Reply With Quote
Old Aug 30th, 2005, 8:29 AM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Wow....that's waaaay more simple then I thought. Wooohoo.
Sane is offline   Reply With Quote
Old Aug 30th, 2005, 7:11 PM   #5
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
You could also probably use PIL to write a function that enables you to save a surface to a PNG or a JPEG. But that's a more complex operation.
Very minimally. Just create the BMP, call Image.open, then Image.save, with the appropriate extension.
Cerulean is offline   Reply With Quote
Old Aug 31st, 2005, 1:07 AM   #6
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Cerulean
Very minimally. Just create the BMP, call Image.open, then Image.save, with the appropriate extension.
Well, sure, if you want the easy way

I was thinking of using "tostring" and "fromstring" (or "frombuffer") to convert between the two without using an intermediate file.
Arevos is offline   Reply With Quote
Old Aug 31st, 2005, 8:52 AM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
I could very easily re-create paint in Python + Pygame then.

Thanks for ze help.
Sane is offline   Reply With Quote
Old Aug 31st, 2005, 12:55 PM   #8
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Yeah. There aren't any Python-based image editors out there are there? Up for a project?
Cerulean is offline   Reply With Quote
Old Aug 31st, 2005, 10:20 PM   #9
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Hmm, I'd need some ideas/motivation. What features could be within an image editor that would be very simple yet usefull and powerful?

I'm thinking a gradiet color fill tool, that'd be neat... hmm what else...
Sane is offline   Reply With Quote
Old Sep 1st, 2005, 9:53 AM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
How about vector graphics?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC