Unity loads images in base64 format

Look at the code first:

Texture2D Base64ToRGBA32(string imageData, int offset = 0)
{
	Texture2D tex2D = new Texture2D(2, 2, TextureFormat.RGB24, false);
	imageData = imageData.Substring(offset);
	byte[] data = Convert.FromBase64String(imageData);
	tex2D.LoadImage(data);
	return tex2D;
}

        Note that the width and height parameters in the Texture2D construction method are both 2, but in fact it will not be converted into a 2*2 image, but the actual size of the image will be used.

        There is also the parameter offset in the Base64ToRGBA32 method. This parameter is mainly to remove the file header in imageData. If there is no file header, it is 0. If there is a file header, the probability is 22.

Guess you like

Origin blog.csdn.net/ttod/article/details/131256680