img2.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import PIL
  2. import PIL.Image
  3. import os
  4. import time
  5. #def SCREEN():
  6. img = PIL.Image.new("RGB", (200, 200))
  7. img.show() # see a black image
  8. pixels = [(255,0,0)]*(200*200)
  9. for i in range(10):
  10. x = (i+20)* (200 )
  11. print(pixels[x])
  12. for j in range(10):
  13. y = j +10
  14. pixels[x+y] = (255,255,255)
  15. img.putdata(pixels)
  16. #print( img)
  17. #image = img
  18. #mode = image.mode
  19. #size = image.size
  20. #data = image.tostring()
  21. #img.show() # see a red image
  22. #input()
  23. import pygame
  24. pg = pygame
  25. pygame.init()
  26. main_size=(600,300)
  27. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  28. #window = pygame.display.set_mode(main_size,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  29. pg.display.set_caption('LibreLight PIL')
  30. this_image = img #pygame.image.fromstring(data, size, mode)
  31. img2 = pygame.image.load(os.path.join( 'brush.png'))
  32. img2 = pygame.transform.scale(img2, (25, 25))
  33. img2.set_colorkey([0,0,0] ) #pygame.image.BLACK)
  34. player_rect2 = img2.get_rect(center=(20, 20))
  35. #window.blit(img2, player_rect2)
  36. #window.blit(img, player_rect2)
  37. #window.blit(img2, player_rect2)
  38. def pilImageToSurface(pilImage):
  39. return pygame.image.fromstring(
  40. pilImage.tobytes(), pilImage.size, pilImage.mode).convert()
  41. pygameSurface = pilImageToSurface(img)
  42. run = True
  43. while run:
  44. #pg.clock.tick(60)
  45. for event in pygame.event.get():
  46. if event.type == pygame.QUIT:
  47. run = False
  48. window.fill(0)
  49. window.blit(pygameSurface, pygameSurface.get_rect(center = (150, 150)))
  50. pygame.display.flip()
  51. exit()
  52. run = 1
  53. while run:
  54. #event_read()
  55. window.fill(0) #[255,0,0])
  56. pygame.display.flip()
  57. pg.time.wait(10)
  58. pygame.quit()
  59. exit()