我正在尝试将RawImage转换为数组字节(bytes[]),但RawImage没有encondePNG或其他东西来为RawImage获取字节,你知道如何获得字节数组吗?
public class RegistryScreen : UIScreen
{
Texture2D pickedImage;
public RawImage[] getRawImageProfile;
public void ChangeIconImage()
{
PickImageFromGallery();
//WebService
mygetImageProfileRequestData = new getImageProfileRequestData();
//this is the problem
mygetImageProfileRequestData.image = getRawImageProfile[0].texture;
}
public void PickImageFromGallery(int maxSize = 1024)
{
NativeGallery.GetImageFromGallery((path) =>
{
if (path != null)
{
// Create Texture from selected image
pickedImage = NativeGallery.LoadImageAtPath(path, maxSize);
////Sust. texture in image(Sprite)
for (int i = 0; i < getRawImageProfile.Length; i++)
{
getRawImageProfile[i].texture = pickedImage;
}
}
Debug.Log("getRawImage: " + getRawImageProfile[0].texture);
}, maxSize: maxSize);
}发布于 2018-11-09 02:11:07
RawImage只是一个呈现分配给其纹理属性的Texture的组件。要获得字节数组,您需要首先访问该Texture,然后将其强制转换为Texture2D。
您的RawImage组件:
public RawImage rawImage;获取它正在渲染的纹理,然后将其强制转换为Texture2D:
Texture2D rawImageTexture = (Texture2D)rawImage.texture;获取png或jpeg格式的字节数组:
byte[] pngData = rawImageTexture.EncodeToPNG();
byte[] jpegData = rawImageTexture.EncodeToJPG();如果您想要RawImage的未压缩数据:
Color32[] rawData = rawImageTexture.GetPixels32();要将Color32[]转换为字节数组,请参阅this post。
https://stackoverflow.com/questions/53213537
复制相似问题