我有一个问题,使用BitConverter.ToDouble()
将字节数组转换为双数组。转换字节数组为双倍的问题
只要我的程序将选择一个图像,然后将图像转换为字节数组。 然后它会将字节数组转换为双数组。
当我将字节数组转换为double时,在循环完成之前会出现此错误。
(目标数组不够长,所有的项目复制收藏。检查数组索引和长度。)
误差在array.Length-7位究竟发生是之前的最后一个最后的第七位在阵列上的位置。
我需要帮助解决这个问题,这里是我的代码:
private Bitmap loadPic;
byte[] imageArray;
double[] dImageArray;
private void btnLoad_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(open.FileName);
loadPic = new Bitmap(pictureBox1.Image);
}
}
catch
{
throw new ApplicationException("Failed loading image");
}
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void btnConvert_Click(object sender, EventArgs e)
{
imageArray = imageToByteArray(loadPic);
int index = imageArray.Length;
dImageArray = new double[index];
for (int i = 0; i < index; i++)
{
dImageArray[i] = BitConverter.ToDouble(imageArray,i);
}
}
public byte[] imageToByteArray(Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, ImageFormat.Gif);
return ms.ToArray();
}
不,这不是它。您正在使用演员阵容,这将产生与BitConverter完全不同的结果。 –
我刚刚澄清了我的帖子,指出基于他的循环(和他的数组初始化),我不认为BitConverter是他想要的。 – Sapph
是的,我认为你是对的。 +1 –