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

ReadPixels doesn't work in flash for scrennshot. What else can I use?

Discussion in 'Flash' started by ArekPoland, May 29, 2012.

  1. ArekPoland

    ArekPoland

    Joined:
    May 25, 2012
    Posts:
    16
    Hi there,

    I'm trying to grab screenshot in application exported to flash.
    In editor Read Pixels works fine. But after publish to swf I have gray picture.
    Below you will find my code.
    If this method is not supported in flash, how I can make a screenshot in application exported to flash?

    Thanks in advance.


    Code (csharp):
    1.  
    2. function Start () {
    3.     MakeScreenshot();
    4. }
    5.  
    6. function MakeScreenshot() {
    7.  
    8.     // We should only read the screen after all rendering is complete
    9.     yield WaitForEndOfFrame ();
    10.  
    11.     // Create a texture the size of the screen, RGB24 format
    12.     var width = Screen.width;
    13.     var height = Screen.height;
    14.     tex = new Texture2D ( width, height, TextureFormat.RGB24, false );
    15.     // Read screen contents into the texture
    16.     tex.ReadPixels ( Rect(0, 0, width, height), 0, 0 );
    17.     tex.Apply ();
    18.     // just for test I put it to GUITexture on screen
    19.         GameObject.Find("shot-preview").GetComponent(GUITexture).texture = tex;
    20.  
    21.     // Encode texture into PNG
    22.     bytes = tex.EncodeToPNG ();
    23.        
    24.     //Destroy ( tex );
    25.  
    26.     */
    27.    
    28.  
    29. }


    I hace also tried use flash native command in this way:


    Code (csharp):
    1.  
    2. var tex = new Texture2D ( width, height, TextureFormat.RGB24, false );
    3.  
    4. ActionScript.Statement("Stage3D.context3D.drawToBitmapData{tex: {0}})", tex);
    5.  
    But still o effect.
    Note that I'm newbie in ActionScript

    Any ideas?
     
  2. woko

    woko

    Joined:
    Oct 11, 2011
    Posts:
    23
    Doesn't work for me either, and neither does RenderTexture. Some workaround would be much appreciated.