Ниже приведен код, который я пытаюсь изменить.
static byte[] GetImageAsByteArray(string imageFilePath)
{
// Open a read-only file stream for the specified file.
using (FileStream fileStream =
new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
{
// Read the file's contents into a byte array.
BinaryReader binaryReader = new BinaryReader(fileStream);
return binaryReader.ReadBytes((int)fileStream.Length);
}
}
Как видите, этот код использует путь к файлу. Я хочу передать изображение Texture2D в метод, как показано ниже:
static byte[] GetImageAsByteArray(Texture2D image)
Как получить тот же вывод, что и для метода файлового потока, но с использованием texture2d. Ниже моя попытка сделать это:
static byte[] GetImageAsByteArray(Texture2D image)
{
/* Open a read-only file stream for the specified file.
using (FileStream fileStream =
new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
*/
{
// Read the file's contents into a byte array.
Debug.Log("MADE IT TO GETIMAGESBYTEARR");
return binaryReader.ReadBytes(image.GetRawTextureData());
}
}