2023-01-22 16:38:23 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2024-08-03 22:24:42 +02:00
|
|
|
|
[AddComponentMenu("")]
|
2023-01-22 16:38:23 +01:00
|
|
|
|
public class CCK_TexImageCreation : MonoBehaviour
|
|
|
|
|
{
|
2024-08-03 22:24:42 +02:00
|
|
|
|
public void SaveTexture(RenderTexture renderTexture, int resWidth = 512, int resHeight = 512)
|
|
|
|
|
{
|
2023-01-22 16:38:23 +01:00
|
|
|
|
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
|
|
|
|
|
RenderTexture.active = renderTexture;
|
|
|
|
|
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
|
|
|
|
|
screenShot.Apply();
|
|
|
|
|
RenderTexture.active = null;
|
|
|
|
|
byte[] bytes = screenShot.EncodeToPNG();
|
|
|
|
|
System.IO.File.WriteAllBytes(Application.persistentDataPath + "/bundle.png", bytes);
|
|
|
|
|
}
|
|
|
|
|
}
|