Sunday, December 4, 2022
HomeGame DevelopmentUtilizing GetRawTextureData() in Unity with non RGBA32 textures?

Utilizing GetRawTextureData() in Unity with non RGBA32 textures?


I’m making an attempt to control a Texture2D utilizing GetRawTextureData<Color32>() as this doesn’t require additional reminiscence to be allotted like GetPixels32() does.

Nevertheless, I can not make sense of the info it’s offering or the way to use it.

GetRawTextureData<Color32>() is instantly suitable with RGBA32 Textures as per: “RGBA32 texture format knowledge format precisely matches Color32 struct” at this web page.

But when a Texture2D is loaded from a JPG byte Array and it has an RBG24 format, the output it gives is nonsense:

        var texelsReal = texture.GetPixels32();
        var texelsColor32 = texture.GetRawTextureData<Color32>();
        var texelsColor = texture.GetRawTextureData<Coloration>();

        for (int i = 0; i < 200; i++)  texture format " + texture.format);
        

This may output one thing like:

TEXEL REAL: RGBA(120, 146, 233, 255) || TEXEL COLOR32: RGBA(225, 146, 190, 174) || TEXEL COLOR: RGBA(0.003, 0.000, 0.000, 183.106) ||Texture Format RGB24

Solely the GetPixels32() model is definitely respectable and the others are whole nonsense.

I want GetRawTextureData<T> to include actual knowledge, as I need to then reallocate pixels by shifting them round utilizing it as per this thread.

However once I strive that at the moment, I get garbled nonsense as a result of I am shifting round nonsense from one place to a different and it then appears to use that nonsense on the finish and smash the picture.

I attempted changing the feel like this:

Texture2D copyTex = new Texture2D(photoThumbT2D.width, photoThumbT2D.top, TextureFormat.RGBA32, false);
bool succeeded = Graphics.ConvertTexture(photoThumbT2D, copyTex);
Debug.Log(" CONVERT SUCCESS " + succeeded + " FORMAT " + copyTex.format + " ORIG " + photoThumbT2D.format);
copyTex.Apply(true); //breaks it for unknown causes...
photoThumbT2D = copyTex;

However this simply creates a gray texture. I used to be instructed within the different thread to make use of a struct like:

public struct RGB24 { public byte r, g, b }

Then presumably:

var texels = texture.GetRawTextureData<RBG24>();

However this offers me an error saying no implicit conversion is feasible. I do not know the way to clear up that if I can.

Any options? Thanks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments