Advertisement
noTformaT

pygame_image.py

Mar 28th, 2011
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. import math
  2. import pygame, sys, os
  3. from pygame.locals import *
  4. pygame.init()
  5. (windows_width, windows_height, windows_title) = (600, 400, "Image Loading")
  6. screen = pygame.display.set_mode((windows_width,windows_height),0,32)
  7. pygame.display.set_caption(windows_title)
  8. windows_bgcolor = (255,255,255)
  9. mainLoop = True
  10. clock = pygame.time.Clock()
  11. milli = seconds = 0.0
  12. #initial data here
  13.  
  14. if pygame.image.get_extended():
  15.     print 'My pygame the best'
  16. else:
  17.     raise SystemExit, 'Sorry, extended image module required'
  18.  
  19. image1 = pygame.image.load(os.path.join('images','img1.jpg'))
  20. image2 = pygame.image.load(os.path.join('images','img2.png'))
  21. image3 = pygame.image.load(os.path.join('images','img3.gif'))
  22. image4 = pygame.image.load(os.path.join('images','img4.bmp'))
  23. image5 = pygame.image.load(os.path.join('images','img5.pcx'))
  24. image6 = pygame.image.load(os.path.join('images','img6.tga'))
  25. image7 = pygame.image.load(os.path.join('images','img7.tif'))
  26. image8 = pygame.image.load(os.path.join('images','img8.png'))
  27.  
  28. newSurf = pygame.Surface((windows_width, windows_height))
  29.  
  30. newSurf.blit(image1, (0,0))
  31. newSurf.blit(image2, (128,0))
  32. newSurf.blit(image3, (256,0))
  33. newSurf.blit(image4, (384,0))
  34. newSurf.blit(image5, (0,128))
  35. newSurf.blit(image6, (128,128))
  36. newSurf.blit(image7, (256,128))
  37. newSurf.blit(image8, (384,128))
  38.  
  39. pygame.image.save(newSurf,os.path.join('images','save_image_1.BMP'))
  40. print "save image_1"
  41.  
  42. stringImage0 = pygame.image.tostring(image1, 'RGB')
  43. stringImage1 = pygame.image.tostring(image8, 'RGB')
  44. stringImage2 = pygame.image.tostring(image8, 'RGBA')
  45. stringImage3 = pygame.image.tostring(image6, 'RGB')
  46.  
  47. #print stringImage
  48.  
  49. newImage0 = pygame.image.fromstring(stringImage0, (128,128), 'RGB')
  50. newImage1 = pygame.image.fromstring(stringImage1, (128,128), 'RGB')
  51. newImage2 = pygame.image.fromstring(stringImage2, (128,128), 'RGBA')
  52. newImage3 = pygame.image.frombuffer(stringImage3, (128,128), 'RGB')
  53.  
  54. newSurf.blit(newImage0, (0,256))
  55. newSurf.blit(newImage1, (128,256))
  56. newSurf.blit(newImage2, (256,256))
  57. newSurf.blit(newImage3, (384,256))
  58.  
  59. pygame.image.save(newSurf,os.path.join('images','save_image_2.JPG'))
  60. print "save image_2"
  61.  
  62. while mainLoop:
  63.     for event in pygame.event.get():
  64.         if event.type == QUIT:
  65.             mainLoop = False
  66.     screen.fill(windows_bgcolor)
  67.     milli = clock.tick(40)
  68.     seconds = milli / 1000.0
  69.     #create frame here
  70.     screen.blit(newSurf, (0,0))
  71.     pygame.display.update()
  72. pygame.image.save(screen,os.path.join('images','img0.BMP'))
  73. pygame.quit()
  74. #destroy data here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement