Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Drawing multiple images on canvas

    Hello!

    i wants to draw multiple images on canvas. can any one give me a simple example.

    thanks..

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Drawing multiple images on canvas

    It's really very easy. Just place two or more images on a main, blank image and put that on the canvas.

    Code:
    import appuifw, e32, graphics
    
    #Define the exit function
    def quit():app_lock.signal()
    appuifw.app.exit_key_handler=quit
    
    def handle_redraw(rect):
         canvas.blit(img)
    
    img=graphics.Image.new((240,320))
    
    img1=graphics.Image.open("C:\\a.jpg")
    img1=graphics.Image.open("C:\\b.jpg")
    img.blit(img1, (20,45))
    img.blit(img2, (200,145))
    
    canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    
    app_lock=e32.Ao_lock()
    app_lock.wait()

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    i have fixed the second img1 to img2 and specified a valid image path.

    i am seeing an empty screen. nothing on the screen.

    still waiting for help.
    Last edited by anees042; 2008-10-16 at 19:52.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Location
    Bhavnagar (India)
    Posts
    112

    Re: Drawing multiple images on canvas

    Quote Originally Posted by anees042 View Post
    i have fixed the second img1 to img2 and specified a valid image path.

    i am seeing an empty screen. nothing on the screen.

    still waiting for help.
    hi nees042,
    Following code shows how to display two images on canvas.
    You can modify co-ordinates to display any number of images on desired locations.

    Code:
    import appuifw
    import e32
    import graphics
    
    def quit():
        app_lock.signal()
    
    img1 = graphics.Image.open(u"c:\\photo1.jpg")
    img2 = graphics.Image.open(u"c:\\photo2.jpg")
    
    canvas=appuifw.Canvas()
    v1,v2 = canvas.size
    
    appuifw.app.body = canvas
    
    canvas.blit(img1,target=(0,0,v1,v2/2))
    canvas.blit(img2,target=(0,v2/2,v1,v2))
    
    appuifw.app.exit_key_handler = quit
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Regards,
    Chintan Umraliya
    - Chintan Umraliya

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    Hello All!

    Thanks for your help!

    Here is my modified working version of the code;
    Code:
    import appuifw, e32, graphics
    
    #Define the exit function
    def quit():app_lock.signal()
    appuifw.app.exit_key_handler=quit
    
    def handle_redraw(rect):
         canvas.blit(img)
    
    # create new image
    img=graphics.Image.new((240,320))
    
    # load an image
    img1=graphics.Image.open("e:\\Images\\goback.gif")
    img2=graphics.Image.open("e:\\Images\\Reply.gif")
    # resize the image
    img3=img1.resize((240,40))
    img4=img2.resize((240,40))
    
    #draw the image
    img.blit(img1, (-2,-92)) # dont know why is it working perfectly, it takes -2 as 2 on x-axis and -92 as 92 on y-axis
    
    img.blit(img2, (0,0), (2,2)) # where 2,2 is x and y-axis
    img.blit(img2, (0,0), (2,32)) # where 2,32 is and y-axis respectively
    img.blit(img2, (0,0), (2,62))
    img.blit(img3, (0,0), (2, 122))
    img.blit(img4, (0,0), (2, 152))
    
    canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    
    app_lock=e32.Ao_lock()
    app_lock.wait()

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    If anyone of you can explain the code further will be helpfull.

    Thanks..

  7. #7
    Registered User
    Join Date
    Jul 2008
    Location
    Bhavnagar (India)
    Posts
    112

    Re: Drawing multiple images on canvas

    Quote Originally Posted by anees042 View Post
    Hello All!

    Thanks for your help!

    Here is my modified working version of the code;
    Code:
    #draw the image
    img.blit(img1, (-2,-92)) # dont know why is it working perfectly, it takes -2 as 2 on x-axis and -92 as 92 on y-axis
    Hi anees,
    Its not taking -2 as 2 or -92 on 92, you have to visualize xy-plane. It will show image according to your co-ordinates.
    you will get it if you check following code.
    Code:
    import appuifw
    import e32
    import graphics
    
    def quit():
        app_lock.signal()
    
    img1 = graphics.Image.open(u"c:\\photo1.jpg")
    
    canvas=appuifw.Canvas()
    appuifw.app.body = canvas
    
    canvas.blit(img1,target=(-50,-50,img1.size[0],img1.size[1]))
    
    appuifw.app.exit_key_handler = quit
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Regards,
    Chintan Umraliya
    - Chintan Umraliya

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    Quote Originally Posted by ck.umraliya View Post
    Hi anees,
    Its not taking -2 as 2 or -92 on 92, you have to visualize xy-plane. It will show image according to your co-ordinates.
    you will get it if you check following code.
    Code:
    import appuifw
    import e32
    import graphics
    
    def quit():
        app_lock.signal()
    
    img1 = graphics.Image.open(u"c:\\photo1.jpg")
    
    canvas=appuifw.Canvas()
    appuifw.app.body = canvas
    
    canvas.blit(img1,target=(-50,-50,img1.size[0],img1.size[1]))
    
    appuifw.app.exit_key_handler = quit
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Regards,
    Chintan Umraliya
    Nothing on the screen after running your code

    Please try my code and then reply me.
    what i see after running my code it was taking -2 as 2 on x-axis and -92 as 92 on y-axis.

    help me understand the code further.

    thanks..

  9. #9
    Registered User
    Join Date
    Jul 2008
    Location
    Bhavnagar (India)
    Posts
    112

    Re: Drawing multiple images on canvas

    hi anees,

    I feel the images we are using are of different size, that can be the reason.
    I have modified code for that.
    It will show half image only. half being on 'negative axis'(not visible but still existing) is hidden.

    Code:
    import appuifw
    import e32
    import graphics
    
    def quit():
        app_lock.signal()
    
    img1 = graphics.Image.open(u"c:\\photo1.jpg")
    canvas=appuifw.Canvas()
    appuifw.app.body = canvas
    
    x=img1.size[0]/2
    y=img1.size[0]/2
    canvas.blit(img1,target=(-x,-y,img1.size[0],img1.size[1]))
    
    appuifw.app.exit_key_handler = quit
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Hope it helps...

    Regards,
    Chintan Umraliya
    Last edited by ck.umraliya; 2008-10-17 at 16:05. Reason: code error
    - Chintan Umraliya

  10. #10
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    Quote Originally Posted by ck.umraliya View Post
    hi anees,

    I feel the images we are using are of different size, that can be the reason.
    I have modified code for that.
    It will show half image only. half being on 'negative axis'(not visible but still existing) is hidden.

    Code:
    import appuifw
    import e32
    import graphics
    
    def quit():
        app_lock.signal()
    
    img1 = graphics.Image.open(u"c:\\photo1.jpg")
    canvas=appuifw.Canvas()
    appuifw.app.body = canvas
    
    x=img1.size[0]/2
    y=img1.size[0]/2
    canvas.blit(img1,target=(-x,-y,img1.size[0],img1.size[1]))
    
    appuifw.app.exit_key_handler = quit
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Hope it helps...

    Regards,
    Chintan Umraliya
    i dont think so as i have tried the code with different images.
    let me check your code.

    Thanks..

  11. #11
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    hello ck.umraliya!

    i checked your code, it is showing the image in the top(half image).

    but the point is that i am passing two parameters while you are passing four parameters.

    mine;
    Code:
    #draw the image
    img.blit(img1, (-2,-92)) # dont know why is it working perfectly, it takes -2 as 2 on x-axis and -92 as 92 on y-axis
    yours;

    Code:
    canvas.blit(img1,target=(-x,-y,img1.size[0],img1.size[1]))
    so for the above, if you try my code and look at the results, it proves my statement which is;

    # dont know why is it working perfectly, it takes -2 as 2 on x-axis and -92 as 92 on y-axis

    now the problem i was having was that i wanted to draw multiple images to the screen.

    so if you look to my code, i have achieved that and i have also understanded it a bit.

    now what i am trying is to understand it further.

    please i am trying to learn it, dont confuse me. if you are proving some thing else which i am not getting then please do so clearly.

    if you wants to prove my statement wrong about this code;

    Code:
    #draw the image
    img.blit(img1, (-2,-92)) # dont know why is it working perfectly, it takes -2 as 2 on x-axis and -92 as 92 on y-axis
    then please try it with different images but with the same method signature.

    also if you explain each parameter of your method will be helpfull.

    thanks..

  12. #12
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Drawing multiple images on canvas

    From the PyS60 Library Reference:
    blit(image[,target=(0,0), source=((0,0),image.size), mask=None, scale=0 ])

    Copies the source area from the given image to the target area in this drawable. The source area is copied in its entirety if mask is not given or is set to None. If the mask is given, the source area is copied where the mask is white. mask can be either None, a 1-bit (black and white) Image or (on S60 2nd edition FP2 and later) a grayscale Image, and must be of the same size as the source image. A grayscale mask acts as an alpha channel, i.e. partial transparency.
    target and source specify the target area in this image and the source area in the given source. They are coordinate sequences of one or two coordinates. If they specify one coordinate, it is interpreted
    as the upper-left corner for the area; if they specify two coordinates, they are interpreted as the top-left and bottom-right corners of the area.
    If scale is other than zero, scaling is performed on the fly while copying the source area to the target area. If scale is zero, no scaling is performed, and the size of the copied area is clipped to the smaller of source and target areas.
    Note that a blit operation with scaling is slower than one without scaling. If you need to blit the same Image many times in a scaled form, consider making a temporary Image of the scaling result and blitting it without scaling. Note also that the scaling performed by the blit operation is much faster but of worse quality than the one done by the resize method, since the blit method does not perform any antialiasing.
    So you can specify one coordinate (in the form of (x,y)) which will be the upper-left corner of the image, or two coordinates (in the form of (x1,y1,x2,y2)) which will be the upper-left and lower-right corners of the image.

  13. #13
    Registered User
    Join Date
    Jul 2008
    Location
    Bhavnagar (India)
    Posts
    112

    Re: Drawing multiple images on canvas

    hi anees,

    Sorry if i confused you. Bogdan has already shown the explaintion. I was not trying to prove your statement wrong, but was trying to tell how negative co-ordinates can be used with image on canvas, however your code is absolutely correct.
    Hope its clear...

    Regards,
    Chintan Umraliya
    - Chintan Umraliya

  14. #14
    Registered User
    Join Date
    Dec 2005
    Posts
    49

    Re: Drawing multiple images on canvas

    Hello!

    Thanks to both of you for your help. i got it now.

    Once again thanks for your help and co-operation.

Similar Threads

  1. Problem in drawing the converted .svg images....
    By pawan_G in forum Symbian Media (Closed)
    Replies: 39
    Last Post: 2008-12-20, 12:44
  2. Replies: 1
    Last Post: 2006-11-15, 08:03
  3. Drawing PNG images against Array Images
    By melas21 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2004-01-19, 22:55
  4. Major problem with delegation to Canvas
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2003-10-08, 17:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×