×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Question mix pictures to one pict

    using this script below, can we mix two or more pictures to one picture ?
    this is for example picture :

    Code:
    import appuifw
    from graphics import *
    import e32
    import key_codes
    import os
    
    appuifw.app.screen = "full"
    appuifw.app.body=canvas=appuifw.Canvas()
    backup_image=Image.new(canvas.size)
    canvas.clear(0)
    center=[0,0]
    zoom=1
    zoomstepindex=0
    screensize=canvas.size
    screenrect=(0,0,screensize[0],screensize[1])
    step=30
    textloc=(screensize[0]*0.3,screensize[1]*.5)
    
    if e32.in_emulator():
        imagedir=u'c:\\images'
    else:
        imagedir=u'e:\\images'
    files=map(unicode,os.listdir(imagedir))
    
    index=appuifw.selection_list(files)
    
    lock=e32.Ao_lock()
    
    def fullupdate():
        backup_image.clear(bgcolor)
        update()
        
    def nextpic():
        global index,finished
        index=(index+1)%len(files)
        finished=1
        loaded_image.stop()
        lock.signal()
    
    def prevpic():
        global index,finished
        index=(index-1)%len(files)
        finished=1
        loaded_image.stop()
        lock.signal()
    
    def zoomin():
        global zoomstepindex,zoom
        if zoomstepindex < (len(zoomsteps)-1):
            zoomstepindex+=1
        zoom=zoomsteps[zoomstepindex]
        fullupdate()
    
    def zoomout():
        global zoomstepindex
        if zoomstepindex > 0:
            zoomstepindex-=1
        zoom=zoomsteps[zoomstepindex]
        backup_image.clear(bgcolor)
        fullupdate()
    
    
    def isvalidcenter(c):
        iw,ih=(loaded_image.size[0],loaded_image.size[1])
        srcsize=(int(screensize[0]/zoom),int(screensize[1]/zoom))
        vw,vh=(srcsize[0]/2,srcsize[1]/2)    
        return (c[0]+vw<iw and c[0]-vw>=0 and
                c[1]+vh<ih and c[1]-vh>=0)
    def move(delta):
        global center
        c=center
        for k in range(1,4):
            t=[c[0]+int(delta[0]*k*20/zoom),
               c[1]+int(delta[1]*k*20/zoom)]
            center=t
            update()
    
    bgcolor=0
    
    canvas.bind(key_codes.EKey3,nextpic)
    canvas.bind(key_codes.EKey1,prevpic)
    canvas.bind(key_codes.EKey5,zoomin)
    canvas.bind(key_codes.EKey0,zoomout)
    canvas.bind(key_codes.EKeyLeftArrow,lambda:move((-1,0)))
    canvas.bind(key_codes.EKeyRightArrow,lambda:move((1,0)))
    canvas.bind(key_codes.EKeyUpArrow,lambda:move((0,-1)))
    canvas.bind(key_codes.EKeyDownArrow,lambda:move((0,1)))
    
    def rect_intersection(r1,r2):
        return (max(r1[0],r2[0]),max(r1[1],r2[1]),
                min(r1[2],r2[2]),min(r1[3],r2[3]))
        
    def update():
        global zoom
        zoom=zoomsteps[zoomstepindex]
        # We convert the screen rect into image coordinates, compute its
        # intersection with the image rect and transform it back to screen
        # coordinates.
        imgrect=(0,0,loaded_image.size[0],loaded_image.size[1])    
        ss=(int(screensize[0]/zoom),int(screensize[1]/zoom))
        screenrect_imgcoords=(center[0]-ss[0]/2,center[1]-ss[1]/2,
                              center[0]+ss[0]/2,center[1]+ss[1]/2)
        sourcerect=rect_intersection(screenrect_imgcoords,imgrect)
        targetrect=(int((sourcerect[0]-center[0])*zoom+screensize[0]/2),
                    int((sourcerect[1]-center[1])*zoom+screensize[1]/2),
                    int((sourcerect[2]-center[0])*zoom+screensize[0]/2),
                    int((sourcerect[3]-center[1])*zoom+screensize[1]/2))
        backup_image.clear(bgcolor)
        backup_image.blit(loaded_image,source=sourcerect,target=targetrect,scale=1)
        if not finished:
            backup_image.text(textloc,u'Loading....',(255,255,0))
        backup_image.text((0,10),files[index],(0,255,0))
        canvas.blit(backup_image)
    
    global finished
    finished=0
    def finishload(err):
        global finished
        finished=1
    
    running=1
    def quit():
        global running,lock
        running=0
        lock.signal()
    
    appuifw.app.title = u"Image Viewer"    
    appuifw.app.exit_key_handler=quit
    backup_image.clear(bgcolor)
    
    selected_file=imagedir+"\\"+files[index]
    imginfo=Image.inspect(selected_file)
    imgsize=imginfo['size']
    loaded_image=Image.new(imgsize)
    
    im=None
    while running:
        selected_file=imagedir+"\\"+files[index]
        imgsize=Image.inspect(selected_file)['size']
        backup_image.text(textloc,u'Loading.',(255,255,0))
        finished=0
        if imgsize != loaded_image.size:
            loaded_image=Image.new(imgsize)
        loaded_image.load(selected_file, callback=finishload)
        backup_image.text(textloc,u'Loading..',(255,255,0))
        zoomsteps=[1.*screensize[0]/loaded_image.size[0],.25,.5,1]
        zoomstepindex=0
        center=[loaded_image.size[0]/2,loaded_image.size[1]/2]    
        backup_image.text(textloc,u'Loading...',(255,255,0))
        while not finished:
            update()
            e32.ao_sleep(0.5)
        fullupdate()
        lock.wait()
    loaded_image=None
    backup_image=None
    thanks for suggest

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

    Re: mix pictures to one pict

    You can find out the size of an image object using the size attribute. So just make an empty image (using Image.new(size)) big enough to hold all the little ones that you want to combine and use the blit method (specifying the target argument as the place where you want to put the small image; this is where you can use the size attribute to calculate the position of each small image) on the large image to put them all together.

    Read the PyS60 Library Reference, the section about the graphics module, for detailed information about everything.

    I strongly recommend that you start a new script and work with just one image until you get it right. Then you can integrate it into the script you posted here. It should be easier that way.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Question Re: mix pictures to one pict

    Quote Originally Posted by bogdan.galiceanu View Post
    You can find out the size of an image object using the size attribute. So just make an empty image (using Image.new(size)) big enough to hold all the little ones that you want to combine and use the blit method (specifying the target argument as the place where you want to put the small image; this is where you can use the size attribute to calculate the position of each small image) on the large image to put them all together.

    Read the PyS60 Library Reference, the section about the graphics module, for detailed information about everything.

    I strongly recommend that you start a new script and work with just one image until you get it right. Then you can integrate it into the script you posted here. It should be easier that way.
    thx for suggestion, i will try it.

    but i want to ask some question.
    a few weeks ago, i tried to open image AN_IMAGE.JPG (473KB, 3678x3366 pixel) using Nokia 7610, but the image won't open. when i simulate in PC, it worked. is that a weakness from a memory phone?
    if i using the script to combine AN_IMAGE.JPG from several pictures, can it will be open on handphone?

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

    Re: mix pictures to one pict

    Quote Originally Posted by bagindraerix View Post
    a few weeks ago, i tried to open image AN_IMAGE.JPG (473KB, 3678x3366 pixel) using Nokia 7610, but the image won't open. when i simulate in PC, it worked. is that a weakness from a memory phone?
    That is a pretty big resolution so it could be that the phone can't handle such large images (the Nokia 7610 is a bit old and might not have been designed for it). But it could be another reason. So you just used Image.open and nothing happened?

    Experiment with images of various resolutions to see which of them work.

    Quote Originally Posted by bagindraerix View Post
    if i using the script to combine AN_IMAGE.JPG from several pictures, can it will be open on handphone?
    Probably. Newer phones don't suffer from such limitations (again, it's possible that old ones don't either, I don't know for sure what the cause of your problem is).

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Re: mix pictures to one pict

    Quote Originally Posted by bogdan.galiceanu View Post
    That is a pretty big resolution so it could be that the phone can't handle such large images (the Nokia 7610 is a bit old and might not have been designed for it). But it could be another reason. So you just used Image.open and nothing happened?

    Experiment with images of various resolutions to see which of them work.



    Probably. Newer phones don't suffer from such limitations (again, it's possible that old ones don't either, I don't know for sure what the cause of your problem is).
    yes, when i tried to open the image, it show nothing.
    i have tried with N73, and the result was same.
    but when i try to open the image with X-Plore application, it can show the image.
    so i confuse why Python can't show the image.


    Originally Posted by bogdan.galiceanu View Post
    You can find out the size of an image object using the size attribute. So just make an empty image (using Image.new(size)) big enough to hold all the little ones that you want to combine and use the blit method (specifying the target argument as the place where you want to put the small image; this is where you can use the size attribute to calculate the position of each small image) on the large image to put them all together.

    Read the PyS60 Library Reference, the section about the graphics module, for detailed information about everything.

    I strongly recommend that you start a new script and work with just one image until you get it right. Then you can integrate it into the script you posted here. It should be easier that way.
    i'm just a newbie, can you show me the code?
    thank you very much for your support

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

    Re: mix pictures to one pict

    Quote Originally Posted by bagindraerix View Post
    yes, when i tried to open the image, it show nothing.
    i have tried with N73, and the result was same.
    but when i try to open the image with X-Plore application, it can show the image.
    so i confuse why Python can't show the image.
    But have you tried other images?

    Quote Originally Posted by bagindraerix View Post
    i'm just a newbie, can you show me the code?
    thank you very much for your support
    The following code takes all the images from a folder and places them next to each other on one line. You can do whatever modifications you need (like placing images on several lines or in a certain order etc.)

    Code:
    import appuifw, graphics, os
    
    
    #Calculate how big the image that will hold the other images should be
    platformx=0
    platformy=0
    
    #Suppose you want to combine all the images in C:\Images
    #and assuming you only have image files there
    for i in os.listdir("C:\\Images"):
    	img=graphics.Image.open("C:\\Images\\"+i)
    	platformx+=img.size[0]  #The sum of the lengths of all the images
    	if img.size[1]>platformy:
    		platformy=img.size[1]  #The height of the tallest image
    
    platform=graphics.Image.new((platformx,platformy))
    
    x=0
    
    #Put them on the big image
    for i in os.listdir("C:\\Images"):
    	img=graphics.Image.open("C:\\Images\\"+i)
    	platform.blit(img, target=(x,0,img.size[0],img.size[1]))
    	x+=img.size[0]
    
    #Save it
    platform.save("C:\\p.jpg")

  7. #7
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    114

    Re: mix pictures to one pict

    Quote Originally Posted by bagindraerix View Post
    yes, when i tried to open the image, it show nothing.
    i have tried with N73, and the result was same.
    but when i try to open the image with X-Plore application, it can show the image.
    so i confuse why Python can't show the image.
    Did you try increasing the heap size of your application? Maybe it is a MemoryError which is hidden from you for some reason. You can try increasing the heap size by using PyS60 application packager(assuming you are using 1.9.x) or using ensymble py2sis '--heapsize' option(1.4.5). Use 200k,8M, this should cover almost all scenarios.
    import antigravity

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Re: mix pictures to one pict

    Quote Originally Posted by bogdan.galiceanu View Post
    But have you tried other images?



    The following code takes all the images from a folder and places them next to each other on one line. You can do whatever modifications you need (like placing images on several lines or in a certain order etc.)

    Code:
    import appuifw, graphics, os
    
    
    #Calculate how big the image that will hold the other images should be
    platformx=0
    platformy=0
    
    #Suppose you want to combine all the images in C:\Images
    #and assuming you only have image files there
    for i in os.listdir("C:\\Images"):
    	img=graphics.Image.open("C:\\Images\\"+i)
    	platformx+=img.size[0]  #The sum of the lengths of all the images
    	if img.size[1]>platformy:
    		platformy=img.size[1]  #The height of the tallest image
    
    platform=graphics.Image.new((platformx,platformy))
    
    x=0
    
    #Put them on the big image
    for i in os.listdir("C:\\Images"):
    	img=graphics.Image.open("C:\\Images\\"+i)
    	platform.blit(img, target=(x,0,img.size[0],img.size[1]))
    	x+=img.size[0]
    
    #Save it
    platform.save("C:\\p.jpg")
    it shows error message:
    Code:
    File "c:\python\Script1.py", line 11, in ? img=graphics.Image.open("C:\\Images\\"+i)
    File "c:\\resource\graphics.py", line 88, in open img=Image(_graphics.ImageOpen(unicode(filename),finish_load))
    SymbianError: [Errno-1]
    KErrNotFound

  9. #9
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Re: mix pictures to one pict

    Quote Originally Posted by ashwinurao View Post
    Did you try increasing the heap size of your application? Maybe it is a MemoryError which is hidden from you for some reason. You can try increasing the heap size by using PyS60 application packager(assuming you are using 1.9.x) or using ensymble py2sis '--heapsize' option(1.4.5). Use 200k,8M, this should cover almost all scenarios.
    is there any other way to try before we package it?

Similar Threads

  1. Picture's gallery
    By djsid in forum Symbian
    Replies: 8
    Last Post: 2008-08-06, 09:25
  2. Nokia 6267 - Pictures and music problems
    By gammexane in forum General Development Questions
    Replies: 1
    Last Post: 2008-03-16, 14:23
  3. RE: MBM File Pictures
    By surprisedisco in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2007-07-05, 11:58
  4. Replies: 5
    Last Post: 2007-06-06, 11:56
  5. having trouble loading pictures
    By cire_re in forum Mobile Java General
    Replies: 3
    Last Post: 2004-08-16, 22:33

Posting Permissions

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