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.


    Trouble using imported images from Photos

    Pythonista
    6
    31
    11188
    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.
    • cvp
      cvp last edited by cvp

      import ui
      from scene import *
      
      class MyScene (Scene):
      	def setup(self):
      		self.background_color = '#000000'
      		ui_image = ui.Image.named('IMG_5903.JPG')	# 5 MB 3672x4896 px   **** Error
      		#ui_image = ui.Image.named('IMG_3735.JPG')	# 4 MB 1536x2048 px **** ok
      		#ui_image = ui.Image.named('IMG_6575.JPG')	# 43 KB 640x853 px  **** ok
      		self.background = SpriteNode(ui_image)
      		self.background.position = self.size.width / 2, self.size.height / 2
      		self.add_child(self.background)
      
      run(MyScene())
      

      No error with photo of 4 Mb but error with photo of 5 Mb

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

        Big photo is here

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

          what if you create the SpriteNode outside of the scene?

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

            @JonB idem

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

              ohh, ok. scene Textures are opengl based, i think. So you cannot have a Texture that is larger in pixels that the graphics memory region, which is something like twice largest screen size (for retina displays).

              with ui.ImageContext(1024*2,1024*2) as ctx:
                 #ui.Image.named('IMG_0625.JPG').draw()
                 Texture(ctx.get_image())
              

              The above works, on my Ipad3. Anything up to 2048 in either row/col works, but even 2049x1 fails. so, that tells me the opengl textures must be <=2048 in either dimension.

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

                @JonB that's ok, thanks for @iOSBrett

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

                  I‘m having a somewhat similar issue, I can’t even load an image that’s 511 kB in size. I haven’t used the scene module for some time now and my memory is a bit rusty, but the following code should run without an issue, right?
                  Here it is:

                  from scene import *
                  import os
                  
                  A = Action
                  class MyScene (Scene):
                  	def setup(self):
                  		img = 'rectangle_1.png'
                  		self.background_color = 'white'
                  		if img in os.listdir(): print('yes') 	#prints 'yes' in console
                  		print(ui.Image.named('IMG_5903.JPG')) #prints None in console
                  		#a = Texture(img) #Image not found
                  		a = SpriteNode(img) #could not load texture
                  		self.add_child(a)
                  		pass
                  	
                  if __name__ == '__main__':
                  	run(MyScene(), show_fps=False)
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • pulbrich
                    pulbrich last edited by pulbrich

                    Wouldn’t you need an

                    import ui
                    

                    before using ui.Image?

                    Drizzel 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      Try

                          img = 'rectangle_1.png'
                          self.background_color = 'white'
                          if img in os.listdir(): print('yes')            
                          printt(ui.Image.named(img)) 
                      

                      You were checking one file, but trying to open a different one

                      1 Reply Last reply Reply Quote 0
                      • Drizzel
                        Drizzel @pulbrich last edited by

                        @pulbrich no, it actually functions. The output is the same if I use “import ui” and when I don’t.

                        @JonB your suggestion prints the following:

                        yes
                        <_ui.Image object at 0x108fe9e40>

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

                          I figured out the issue. Whenever I import an image from my camera roll, it’s ending is in caps (.PNG). Renaming it to .png causes the issue, so I’m just going to not do that :)

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