Search Unity

Trouble Cropping Texture2d Using GetPixels

Discussion in 'Scripting' started by Destructicorn, Dec 21, 2014.

  1. Destructicorn

    Destructicorn

    Joined:
    Feb 19, 2013
    Posts:
    4
    I'm trying to crop Texture2D loaded from WWW into another Texture2D using the code below. The issue i'm having is when the length and width pass a certain value I just a grey (blank) texture back. I'm using it on Android if that makes any difference.

    Texture2D loadedTexture = new Texture2D( 128, 128, TextureFormat.RGB24, false );
    WWW.LoadImageIntoTexture( loadedTexture );

    //Using hard coded values for testing, texture width and height exceed these
    Texture2D croppedTexture = new Texture( 900, 900 );
    croppedTexture.SetPixels( loadedTexture.GetPixels( 0, 0, 900, 900 ) );
    croppedTexture.Apply( false );

    loadedTexture = croppedTexture;

    In my onGUI function i'm calling a draw texture on loadedTexture.

    Edit:
    I printed out the Color array from GetPixels and the colors are not all gray so I'm confused as to what is happening.
     
    Last edited: Dec 21, 2014