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
-
So the photo module as asset is the issue.
-
@FuckingNerd No idea, try to import your photo as a local Pythonista file and then use it as texture
-
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 ?
-
@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
-
Did that. No color invert. So it’s the asset.
-
@FuckingNerd I guess, sorry, I can't help more 😢
-
Helps for the effort man!
-
@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
-
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”.
-
-
@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.