Advertisement
here2share

# picture_resize.py

Jan 9th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # picture_resize.py
  2.  
  3. from appuifw import *
  4. from graphics import *
  5. import e32,appuifw,os,sys,key_codes,time,math,graphics,sensor,string # No anti-alias or nearest?
  6.  
  7. def draw(rect):
  8.     try: canvas.blit(img)
  9.     except: pass
  10.  
  11. def quit():
  12.     script_lock.signal()
  13.  
  14. canvas = appuifw.Canvas(redraw_callback=draw)
  15. appuifw.app.directional_pad=False
  16. appuifw.app.orientation='portrait'
  17. appuifw.app.screen='large'
  18. appuifw.app.body=canvas
  19. w,h = canvas.size
  20. img=graphics.Image.new((w,h))
  21.  
  22. sample = Image.open(unicode('e:\\python\\320x320.jpg')) # of a 3D Python Logo
  23. def actual():
  24.     img.clear((0,0,0))
  25.     img.blit(sample)
  26.     draw(())
  27. def stretch():
  28.     img.clear((0,0,0))
  29.     img.blit(sample,scale=2)
  30.     draw(())
  31. def shrink():
  32.     img.clear((0,0,0))
  33.     img.blit(sample.resize((120, 120)),target=(200,200))
  34.     draw(())
  35. appuifw.app.menu = [(u'Actual Size', actual), (u'Stretch To Fit', stretch), (u'Shrink To 120x120', shrink) ]
  36.  
  37. img.clear((0,0,0))
  38. img.blit(sample)
  39. draw(())
  40.  
  41. lock = e32.Ao_lock()
  42. appuifw.app.exit_key_handler = lambda:lock.signal()
  43. lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement