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.


    Image.UI gets color inverted if photo is PNG

    Pythonista
    2
    20
    1069
    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.
    • FuckingNerd
      FuckingNerd last edited by

      So the photo module as asset is the issue.

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

        @FuckingNerd No idea, try to import your photo as a local Pythonista file and then use it as texture

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

          I have no idea how to access those imported files(never done it). This is not the way it seems. Can you help me out ?

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

            @FuckingNerd I think you have correctly imported some images and you can replace in my little script my 1 - 97f7tRn.png by one of your IMG_xxxx.PNG

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

              Did that. No color invert. So it’s the asset.

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

                @FuckingNerd I guess, sorry, I can't help more 😢

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

                  Helps for the effort man!

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

                    @FuckingNerd Perhaps, you could

                    • get the asset as an ui.Image
                    • write it as a local (temporary) file
                    • use it as Texture
                    • remove the local file
                    1 Reply Last reply Reply Quote 0
                    • FuckingNerd
                      FuckingNerd last edited by FuckingNerd

                      I was able to solve the problem.

                      Instead of using asset.get_ui_image() and pass it on to SpriteNode(Texture(..ui_image..)) I got a PIL image directly with asset.get_image() and transformed it with the scripts found here to and ui image.

                      relevant from above link:

                      # pil <=> ui
                      def pil2ui(imgIn):
                      	with io.BytesIO() as bIO:
                      		imgIn.save(bIO, 'PNG')
                      		imgOut = ui.Image.from_data(bIO.getvalue())
                      	del bIO
                      	return imgOut
                      

                      I hope you find this useful google hero from the future. This solves “weird false inverted colors for PNG ui.image from assets in photo module”.

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

                        @FuckingNerd 👍

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

                          @FuckingNerd you could try Asset.get_image_data which could be quicker

                          Asset.get_image_data(original=False)
                          Fetch the asset’s image data, and return it as a io.BytesIO object. 
                          You can use io.BytesIO.getvalue() to get the image data as a byte string.
                          
                          By default, the most recent version of the image is returned; 
                          pass original=True to get the image without any adjustments/edits.
                          
                          If you only need the image for saving it as a file, 
                          this is more efficient than Asset.get_image(). 
                          The returned io.BytesIO has an additional uti attribute 
                          that can be used to determine the file type of the image data.
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors