我现在在显示现有文件中的图像时遇到问题...
try
{
bool EndFlag = false;
string fileLoc = @"../../../../samples/jpeg_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".jpg";
//Create a file Stream to save the body of the JPEG File content.
FileStream fs = null;
fs = new FileStream(fileLoc, FileMode.OpenOrCreate, FileAccess.Write);
do
{
ReadJpegFileCommand();
CamPort.DiscardOutBuffer();
CamPort.DiscardInBuffer();
for (int i = 0; i < 5; i++)
header[i] = (byte)CamPort.ReadByte();
if (((int)header[0] == 0x76) && (header[1] == 0x00) && (header[2] == 0x32) && (header[3] == 0x00) && (header[4] == 0x00))
{
for (int i = 0; i < 32; i++)
ImageBody[i] = (byte)CamPort.ReadByte();
/*
* writing the bytes that have been read till now to a file
*/
fs.Write(ImageBody, 0, ImageBody.Length);
for (int i = 1; i < ImageBody.Length; i++) // check if reached to the last two bytes(FF D9) of the body to stop reading the body.
{
if ((ImageBody[i - 1] == 0xFF) && (ImageBody[i - 0] == 0xD9))
{
EndFlag = true;
MessageBox.Show("FFD9 has been received");
OneSnap.Image =(Bitmap)System.Drawing.Image.FromStream(fs);
fs.Close();
}
}
}
else
{
MessageBox.Show("Error,Try again"); // The first 5 bytes does not match the header
}
for (int i = 0; i < footer.Length; i++)
{
footer[i] = (byte)CamPort.ReadByte();
}
// update the starting address
M += (UInt16)ImageBody.Length;
//Progress.PerformStep();
}while(!EndFlag);
}
catch (System.Exception ex) { MessageBox.Show(ex.Message); }
当我使用此语句时:
OneSnap.Image =(Bitmap)System.Drawing.Image.FromStream(fs);
fs.Close();
我有这个错误:“参数无效”
但是当我尝试使用替代方法并将之前的陈述替换为::
fs.Close();
OneSnap.Image =(Bitmap)System.Drawing.Image.FromFile(fileLoc);
我在图片框中显示了图像..但是当我执行程序更多时出现此错误::“内存不足”并且看不到图片框中的图像(OneSnap)>>>如何解决这个 ??
示例 ::(此图像已通过链接 Sprite Jpeg Camera 捕获)