Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Image/canvas bliting (See related posts)

I can't remember how to call the blit method.
So, here's just a personal reminder.
(BTW, the pys60 doc has a wrong order between target and source)
   1  
   2  app.body = c = Canvas()
   3  w,h = 20,20
   4  im = Image.new(size=(w,h))
   5  
   6  # here's prototype
   7  # blit(im, source=(0,0,w,h), target=(0,0), mask=None, scale=0)
   8  # here are examples
   9  c.blit(im)  # put entire image on top-left
  10  c.blit(im, target=(70,70)) # put it about mid-screen
  11  c.blit(im, (0,0,w/2,h/2))  # put a quater image on top-left
  12  
  13  # double the image size and put it about mid-screen
  14  c.blit(im, target=(60,60,100,100), scale=1)

If scale is not specified and source <> target, the image
will be clipped instead of resized.

mask is a 1-bit image with the same size as image.
   1  mask = Image.new((w,h),'1')

Pixel on the image will be copied if the same pixel
on the mask is 'white'.
So we can use mask to make 'Sprite'.

You need to create an account or log in to post comments to this site.


Click here to browse all 5827 code snippets

Related Posts