![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() |
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?
|
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
You can save a surface as a BMP or TGA file with:
pygame.image.save(surface, file) |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
Wow....that's waaaay more simple then I thought. Wooohoo.
![]() |
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#6 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
![]() I was thinking of using "tostring" and "fromstring" (or "frombuffer") to convert between the two without using an intermediate file. |
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
I could very easily re-create paint in Python + Pygame then.
![]() Thanks for ze help. |
|
|
|
|
|
#8 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Yeah. There aren't any Python-based image editors out there are there? Up for a project?
![]() |
|
|
|
|
|
#9 |
|
Programming Guru
![]() |
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... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|