Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

EncodeToPNG doesn´t work on Android

Discussion in 'Scripting' started by namba02250, May 2, 2015.

  1. namba02250

    namba02250

    Joined:
    Feb 6, 2015
    Posts:
    19
    Hello everyone, i hope somebody can help me with this, im trying to save a byte array to a png file, so im using the method EncodeToPNG and is not working on Android devices. Do you know how to fix it, or other way to do it.

    (I'm using Unity 4.6)

    THANKSS.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    By EncodeToPNG, do you mean the function on Texture2D called 'EncodeToPNG'?

    http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToPNG.html

    Also, what's not working about it? Do you get an error? What is that error? At what part of the encoding and saving steps does it fail to work? Is it the encoding, or the actual saving to disk?

    You didn't give us enough information to go on.
     
  3. namba02250

    namba02250

    Joined:
    Feb 6, 2015
    Posts:
    19
    byte[] bytes = photo.EncodeToPNG(); (the error is ocurring in this line).

    when i try it on my pc, it works perfectly, but is not working when i try it in Android
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    And what's the error you get?
     
    Bunny83 likes this.
  5. namba02250

    namba02250

    Joined:
    Feb 6, 2015
    Posts:
    19
    .. i dont know how to see the error in android devices, i just know is not passing that line
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    how do you know it's that line specifically?

    Try wrapping the whole save process in a try/catch statement, and log the exception in the catch.
     
  7. pws-devs

    pws-devs

    Joined:
    Feb 2, 2015
    Posts:
    63
  8. namba02250

    namba02250

    Joined:
    Feb 6, 2015
    Posts:
    19
    thank you! i solved the problem with all your help
     
  9. Bamboo-Panda

    Bamboo-Panda

    Joined:
    Apr 6, 2016
    Posts:
    3
    Hi, how you fixed this? I encountered the same problem, but in iOS. It just said bad_access and aborted. I cannot figure out the reason. And for Texture2D.LoadImage(), it appeared a similar problem, but said "Wrong JPEG library version: library is 62,caller expects 61".
     
  10. Yamist

    Yamist

    Joined:
    Jan 5, 2017
    Posts:
    1
    it should be illegal to write this sentence and not explain what the issue was
     
  11. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,064
    Bunny83 likes this.