Hi.
It encounters the problem that EncodeToPNG doesn’t operate normally by Unity3.4.
The image breaks or it is not correctly displayed on Android though it vomits in the Android terminal with System.IO.File.WriteAllBytes after the read texture is made a byte with EncodeToPNG.
The image was correctly displayed here when returning to Unity3.3 by way of experiment and having tried.
Will this be a bug in Unity3.4?
public void TapWPButton()
{
string gRootPath = "";
if(Application.platform == RuntimePlatform.Android)
{
if(!Directory.Exists( "/mnt/sdcard/Android/data/WallPaper" ) )
{
Directory.CreateDirectory( "/mnt/sdcard/Android/data/WallPaper" );
}
gRootPath = "/mnt/sdcard/Android/data/WallPaper/";
}
else
{
if(!Directory.Exists("C:/WallPaper")){
Directory.CreateDirectory("C:/WallPaper");
}
gRootPath = "C:/WallPaper/";
}
StartCoroutine( CopyTexture( gRootPath ) );
}
public IEnumerator CopyTexture( string path )
{
yield return new WaitForEndOfFrame();
Texture2D Image = new Texture2D( Tex.width, Tex.height, TextureFormat.RGB24, false );
Image.SetPixels( Tex.GetPixels() ); // Tex is Read PNG image
Image.Apply();
byte[] bytes = Image.EncodeToPNG();
Destroy( Image );
System.IO.File.WriteAllBytes( path + "WallPaper.png", bytes );
}
Please help
Thanks