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.


    Containers for photos, with scroll, drag&drop between them

    Pythonista
    2
    47
    16860
    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.
    • jmv38
      jmv38 @cvp last edited by

      @cvp 5000 doesnt work for me and 5000<7000

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @jmv38 last edited by

        @jmv38 and Sure that you don't have two pixels py point?
        What is your device?

        jmv38 2 Replies Last reply Reply Quote 0
        • jmv38
          jmv38 @cvp last edited by

          @cvp i do have 2 pixels per point (ipad air)
          i dont crash, it is just that the image saved is black
          i checked that 4x1024 is ok and 4x1025 fails
          i remember this ios limit 4096 from somwhere.

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @jmv38 last edited by

            @jmv38 could you post your code, only this part, and the image you use?

            1 Reply Last reply Reply Quote 0
            • jmv38
              jmv38 @cvp last edited by

              @cvp just to let you know here is my code.
              It wont run because the rest of the code is missing, but it gives you the idea

              def save(self):
                  # make a hi resolution copy of back & images, then save it in camera roll
                  xo, yo, w, h = self.page.back.frame
                  c = self.page.back.background_color
                  targetWidth = 4*1024
                  s = targetWidth / w
                  w, h = w*s, h*s
                  page = ui.View( frame=(0,0,w,h), background_color=c)
                  views = []
                  for thumb in self.thumbs:
                    x,y,w,h = thumb.frame
                    x,y,w,h = (x-xo)*s, (y-yo)*s, w*s, h*s
                    v = ui.View( frame=(x,y,w,h) )
                    x,y,w,h = thumb.iv.frame
                    x,y,w,h = x*s, y*s, w*s, h*s
                    img = thumb.getImage(thumb.asset)
                    iv = ui.ImageView(frame=(x,y,w,h), image=img)
                    v.add_subview(iv)
                    page.add_subview(v)
                    views.append(v)
                  # save page image in pythonista
                  getTopView().add_subview(page)
                  #page.bring_to_front()
                  #if True: return
                  path = 'temp.jpg'
                  with ui.ImageContext(page.width, page.height) as ctx:
                    page.draw_snapshot()                            
                    ui_image = ctx.get_image()
                  pil = Image.open(io.BytesIO(ui_image.to_png()))
                  pil.save(path , quality=99)
                  # save page image in albums
                  asset = photos.create_image_asset(path)
                  os.remove(path)
                  getTopView().remove_subview(page)
                  views = False
                  console.hud_alert('saved')
              

              looks like i must add the view to the screen to get the draw snapshot to work.

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @jmv38 last edited by

                @jmv38 said:

                looks like i must add the view to the screen to get the draw snapshot to work.

                Not at all, I think. You've seen my little code, nothing goes to the screen

                jmv38 1 Reply Last reply Reply Quote 0
                • jmv38
                  jmv38 @cvp last edited by

                  @cvp you are correct. My pb was pbly sthg else.

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @jmv38 last edited by

                    @jmv38 The only 4096 limit I find for iPad Air is Max OpenGL Texture Sizes

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

                      From here

                      The UIImage documentation (as of iOS 10) no longer seems to mention size limitations, although if you use UIImageView with images whose dimensions are larger than the maximum texture size* supported by the device you happen to be using you do get very large memory consumption at render time.

                      (The memory consumption I see in Instruments seems to indicate that the entire image is put into a 32 bits per pixel buffer when the CA::Layer is rendered.)

                      If your app doesn't get kill by the OS due to memory usage, the UIImageView does still end up displaying the image though.

                      Given this, you'll still need strategies to deal with very large images.

                      • You can check the maximum texture size using something like glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);. Just make sure you've set the EAGLContext current context to be something non-nil before querying OpenGL, otherwise you'll get zero.
                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp last edited by

                        I've tried in ObjectiveC, following this and this

                        and I have same crash with very big files of more than 25MB

                        # https://gist.github.com/jsbain/389a67c5aacb097b87fd
                        # https://github.com/tdamdouni/Pythonista/blob/master/_2017/core_image.py
                        import ui
                        from objc_util import *
                        import ctypes
                        import os
                        
                        iv = ui.ImageView()
                        iv.image = ui.Image.named('P1020096.JPG') # 3888 x 2592 pixels
                        wi,hi = iv.image.size
                        iv.frame = (0,0,wi,hi)
                        print(wi,hi)															# 3888 2592
                        w = 7000
                        h = w*hi/wi
                        print(w,h)																# 7776 5184
                        with ui.ImageContext(w,h) as ctx:
                        	iv.draw_snapshot()
                        	ui_image = ctx.get_image()
                        uio = ObjCInstance(ui_image)
                        c.UIImageJPEGRepresentation.argtypes = [c_void_p, CGFloat]
                        c.UIImageJPEGRepresentation.restype = c_void_p
                        quality = 1.0
                        data = ObjCInstance(c.UIImageJPEGRepresentation(uio.ptr, quality))
                        filename = os.path.abspath('t1.jpg')
                        data.writeToFile_atomically_(filename, True)
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors