所以,我有以下脚本将图像转换为二进制文件(所以我可以把它放在一个 blob 上):
public static byte[] ImagemBin(string imagePath, int imagem_comp)
{
FileStream fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[imagem_comp];
int numBytesToRead = imagem_comp;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = fileStream.Read(buffer, numBytesRead, numBytesToRead);
// Break when the end of the file is reached.
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
numBytesToRead = buffer.Length;
fileStream.Read(buffer, 0, numBytesToRead);
fileStream.Close();
return buffer;
}
其中imagePath是图片在电脑中的位置,imagem_comp是图片的大小。但是,图像转换不完整,几个字节后,它返回唯一的0...
那么,对此有什么帮助吗?
先感谢您。