既存のファイルからの画像の表示に問題があります...
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によってキャプチャされています)