Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Result of Texture2D.ReadPixels() is a texture completely blue

Discussion in 'Tizen' started by nicoplv-auto, Jun 27, 2017.

  1. nicoplv-auto

    nicoplv-auto

    Joined:
    May 28, 2013
    Posts:
    10
    Hi everyone, I working currently on a game for Tizen platform and I have a little issue concerning Texture2D.ReadPixels()

    I explain you quickly the problem, in my game, I need screenshot a camera and display the render on a UI, to do that I use Texture2D.ReadPixels() and display the texture2D on an UI image raw.

    On all platforms, everything working great, even on the Tizen emulator, but when I try with a "real" Tizen device, the result of ReadPixels is a texture completely blue.

    I attach you a picture of that, the result is the blue square in the center:

    TizenReadPixelsBug.jpg

    On all the other platforms, I have this result:

    TizenReadPixelsBug-03.jpg

    I saved the texture on the phone to be sure the problem isn't the display on the image raw ... and the result is the same an image completely blue.

    Last information, I start, I built my app with unity 5.5.0, now I build with 5.6.2 and the result is not exactly the same, the UI is displayed on the screenshot:

    TizenReadPixelsBug-02.jpg

    I looked the features currently not supported by Unity Tizen and I didn't see ReadPixels so ... I don't know what is the problem.

    Has this ever happened to anyone ? And did you find how solve it ? Thank you
     
  2. Jaehyun

    Jaehyun

    Unity Technologies

    Joined:
    Feb 4, 2014
    Posts:
    55
    I couldn't reproduce this problem on Z1 and z2, and Z3.
    Could you share the codes you are using? (and settings of Main Camera too)
     
  3. nicoplv-auto

    nicoplv-auto

    Joined:
    May 28, 2013
    Posts:
    10
    Ok thank you for your reply, I have extracted the codes I am using:
    Code (C#):
    1. public IEnumerator GrabPicture()
    2. {
    3.     yield return new WaitForEndOfFrame();
    4.  
    5.     // Calculate screenshot size
    6.     int width = Screen.width;
    7.     int height = Mathf.FloorToInt(Screen.width / ratio);
    8.     if (width > Screen.height)
    9.     {
    10.         width = Mathf.FloorToInt(Screen.height * ratio);
    11.         height = Screen.height;
    12.     }
    13.  
    14.     // Calculate margin
    15.     int marginWidth = Mathf.FloorToInt((Screen.width - width) / 2f);
    16.     int marginHeight = Mathf.FloorToInt((Screen.height - height) / 2f);
    17.  
    18.     // Capture
    19.     Texture2D screenshotTexture = new Texture2D(width, height, TextureFormat.RGB24, false);
    20.     screenshotTexture.ReadPixels(new Rect(marginWidth, marginHeight, width, height), 0, 0, false);
    21.     screenshotTexture.Apply();
    22.  
    23.     // Save picture on file
    24.     byte[] bytes = screenshotTexture.EncodeToJPG();
    25.     string screenshotPathFull = screenshotPath + ((screenshotPath == "") ? "" : "/") + screenshotName + ".jpg";
    26.     File.WriteAllBytes(screenshotPathFull, bytes);
    27.  
    28.     // Callback
    29.     if (callbackGrabPath != null)
    30.         callbackGrabPath(screenshotPathFull);
    31.     if (callbackGrabTexture != null)
    32.         callbackGrabTexture(screenshotTexture);
    33.     if (callbackGrabPathTexture != null)
    34.         callbackGrabPathTexture(screenshotPathFull, screenshotTexture);
    35. }
    36.  
    I just call StartCoroutine(GrabPicture()); in an OnClick event attach to an UI button.

    And for the settings of the camera:
    TizenReadPixelsBug-04.jpg
     
  4. nicoplv-auto

    nicoplv-auto

    Joined:
    May 28, 2013
    Posts:
    10
  5. nicoplv-auto

    nicoplv-auto

    Joined:
    May 28, 2013
    Posts:
    10
    Ok, I finally find the problem, and it's not coming only of the methods screenshotTexture.ReadPixels.
    The problem was at the same time, I activate a RenderTexture on the camera.