omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Displaying portion of image to screen, scroll to rest of it.

    Pythonista
    2
    3
    2780
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mmontague
      mmontague last edited by mmontague

      I have a question about the right way to go about something, in general terms...

      I have a large image (I can scale it to the width of the screen, but it will still be about twice the height of the screen). I would like to show just a part of the image that will fit on the screen, and then be able to scroll through the image to view different parts of it (using buttons or whatever).

      But I am unsure of the best way to handle the displaying of the larger-than-screen-size image. I have it working now by creating a layer that is the width of the screen but twice the height of the screen, and then setting this Layer's image property to my image:

        im = Image.open("bgnd.png").convert('RGBA') 
        w = int(self.bounds.w) # width of screen
        h = int(im.size[1] * self.bounds.w / im.size[0]) # scale height keep aspect ratio
        im = im.resize((w,h)) # scale image to fit screen width; image height > screen height
        self.im_layer=Layer(Rect(0,0,w,h)) # this layer is larger than screen!
        self.root_layer.add_layer(self.im_layer)
        self.im_layer.image = load_pil_image(im)
      

      This seems to work, but it feels wrong...

      Is setting a Layer to be larger than the screen size OK to do? What does Pythonista do with the portion of the image that is off screen? Could this be problematic if the image were larger, say 10x the height of the screen? How should this issue -- scrolling through a image larger than the screen -- be handled in applications and on the pythonista platform in particular?

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        The current beta does not allow me to replicate your code but my sense is that you are doing it correctly...

        All modern GUI devices can deal gracefully with images that are larger than the screen size. So, setting a scene.Layer to be larger that the screen size is ok to do. Pythonista can deal with a Layer that is larger than the screen resolution and will happily display just the part that fits on the screen and is smart enough not to draw content that is not on screen. As long as your Layer size is not larger than all available RAM in your device, it should work as expected.

        Your code above is focused on scene.Scenes but you might want to read thru the ui.ScrollView docs to see how the ui module deals with larger-than-screen images.

        mmontague 1 Reply Last reply Reply Quote 1
        • mmontague
          mmontague @ccc last edited by

          @ccc That is helpful information, thanks.

          OK, I didn't even know that ui.ScrollView existed. That is going to come in handy!

          m

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors