private void OnSnapshot(object sender, Camera.SnapshotArgs sna) { // try { if (sna.Status == Camera.SnapshotStatus.Ok) { // System.IO.FileStream fs = new System.IO.FileStream(sna.Filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader reader = new System.IO.BinaryReader(fs); byte[] bytes = reader.ReadBytes((int)fs.Length); reader.Close(); string filename = sna.Filename.Substring(this.mCamera.SnapshotFile.Directory.Length + 1); if (Freight.FreightGateway.SaveImage(filename, bytes)) { this.mCamera.SnapshotFile.Filename = ""; this.mCamera.ImprintCaptionString = ""; this.mCamera.Streaming = false; this.mnuSnap.Enabled = false; this.txtComment.Text = ""; MessageBox.Show(sna.Filename + " was saved."); } else { MessageBox.Show(sna.Filename + " was NOT saved."); } } else { MessageBox.Show("Snapshot Error!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// this event is called async by the Camera object after the SnapShot method was called /// </summary> /// <param name="sender"></param> /// <param name="snArgs"></param> void IntermecCamera_SnapshotEvent(object sender, Camera.SnapshotArgs snArgs) { addLog("IntermecCamera_SnapshotEvent entered..."); Cursor.Current = System.Windows.Forms.Cursors.Default; if (snArgs.Status == Camera.SnapshotStatus.Ok) { addLog("SnapshotEvent OK"); _fileName = snArgs.Filename; //rename file to fixed named file try { addLog("SnapshotEvent: Renaming file '" + _fileName + "' to '" + _tempFileName + "'"); System.IO.File.Move(_fileName, _tempFileName); addLog("SnapshotEvent: File rename success"); _fileName = _tempFileName; } catch (Exception) { addLog("SnapshotEvent: File rename FAILED"); } OnImageReady(new EventArgs());//inform about image is ready #if STREAMING_ON #if USEGDI showImage(_fileName); #endif #endif //the following will give Out-of-memory exceptions! //CameraPreview.Image = new Bitmap(_fileName); //########################################### //System.Drawing.Bitmap _bitmap = new Bitmap(_fileName); //Graphics g = Graphics.FromImage(new System.Drawing.Bitmap(_fileName)); //OOM exception //g.DrawImage(this.CameraPreview.Image, // new Rectangle(CameraPreview.Left, CameraPreview.Top, CameraPreview.Right, CameraPreview.Bottom), // new Rectangle(0,0,480,400), // GraphicsUnit.Pixel);// = new System.Drawing.Bitmap(_fileName); } else { System.Diagnostics.Debug.WriteLine("SnapshotEvent not OK: " + snArgs.Status.ToString()); System.Diagnostics.Debug.WriteLine("File: '" + IntermecCamera.SnapshotFile.Directory + "' '" + IntermecCamera.SnapshotFile.Filename + "'"); Cursor.Current = System.Windows.Forms.Cursors.Default; #if USEGDI showSnapshot(false); #endif } #if STREAMING_ON addLog("SnapshotEvent: we DO NOT SWITCH streaming"); #else addLog("SnapshotEvent() IntermecCamera.Streaming=false..."); IntermecCamera.Streaming = false; //do not show streaming automatically #endif _bTakingSnapShot = false; System.Diagnostics.Debug.WriteLine("...IntermecCamera_SnapshotEvent ended."); }
/// <summary> /// this event is called async by the Camera object after the SnapShot method was called /// </summary> /// <param name="sender"></param> /// <param name="snArgs"></param> void IntermecCamera_SnapshotEvent(object sender, Camera.SnapshotArgs snArgs) { addLog("IntermecCamera_SnapshotEvent entered..."); //Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; //as the snapshot event is fired on the end of the snapshot is ready, //we have to set the WaitCursor before starting the snapshot if (snArgs.Status == Camera.SnapshotStatus.Ok) { addLog("SnapshotEvent OK"); _fileName = snArgs.Filename; //rename file to fixed named file try { //first delete a possibly exisiting file, otherwise File.Move will fail with UnauthorizedAccess try { if (System.IO.File.Exists(_tempFileName)) { System.IO.File.Delete(_tempFileName); } } catch (Exception ex) { addLog("SnapshotEvent: Deleting file '" + _tempFileName + "' FAILED: " + ex.Message); } addLog("SnapshotEvent: Renaming file '" + _fileName + "' to '" + _tempFileName + "'"); System.IO.File.Move(_fileName, _tempFileName); addLog("SnapshotEvent: File rename success"); _fileName = _tempFileName; } catch (Exception ex) { addLog("SnapshotEvent: File rename FAILED: " + ex.Message); } OnImageReady(new EventArgs());//inform about image is ready #if STREAMING_ON showImage(_fileName); #endif //the following will give Out-of-memory exceptions! //CameraPreview.Image = new Bitmap(_fileName); //########################################### //System.Drawing.Bitmap _bitmap = new Bitmap(_fileName); //Graphics g = Graphics.FromImage(new System.Drawing.Bitmap(_fileName)); //OOM exception //g.DrawImage(this.CameraPreview.Image, // new Rectangle(CameraPreview.Left, CameraPreview.Top, CameraPreview.Right, CameraPreview.Bottom), // new Rectangle(0,0,480,400), // GraphicsUnit.Pixel);// = new System.Drawing.Bitmap(_fileName); } else //Camera.SnapshotStatus.Ok { System.Diagnostics.Debug.WriteLine("SnapshotEvent not OK: " + snArgs.Status.ToString()); System.Diagnostics.Debug.WriteLine("File: '" + IntermecCamera.SnapshotFile.Directory + "' '" + IntermecCamera.SnapshotFile.Filename + "'"); showSnapshot(false); //show preview } #if STREAMING_ON addLog("SnapshotEvent: we DO NOT SWITCH streaming"); #else addLog("SnapshotEvent() IntermecCamera.Streaming=false..."); IntermecCamera.Streaming = false; //do not show streaming automatically #endif _bTakingSnapShot = false; _bInDeltaProcessing = false; _bLastState = false; //enable OnState processing System.Diagnostics.Debug.WriteLine("...IntermecCamera_SnapshotEvent ended."); Cursor.Current = Cursors.Default; //snapshot event }