I want to make a programm with Unity that shows in split screen on the left side the .jpg or .png image and on the right side the compressed image (ETC or DXT).
I was trying to solve it like this:
void CompressImage()
{
original_image = new Texture2D(Screen.height, Screen.width, TextureFormat.ASTC_RGBA_12x12, false);
GetComponent<Renderer>().material.mainTexture = original_image;
}
public void OnGUI()
{
GUI.DrawTexture(new Rect(0, 0, original_image.height, original_image.width), original_image);
}
Am I doing the compression the right way? When I try do show the compressed image there is no image to see but some random colors.
I am new to this and it would be nice if someone could help me with this. Thank you
You can do this only in editor. Builds can only convert textures in basic format.
You can use Texture2D.Compress method to compress texture into DXT format, or EditorUtility.CompressTexture for more formats but it's only available in Editor.
You get random colors because you create texture but not provide any data into it. So in the memory you have garbage.
EDIT
Unity is stripping the code responsible for texture compression from the build because no one is using it, it's slow and the builds must be as small as possible. If you really need compression in your build you have to implement it by yourself or find a library for it.