private void frmViewer_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) { if (Properties.Settings.Default.ClosePrompt == false || (Properties.Settings.Default.ClosePrompt && frmClose.ShowDialog() == System.Windows.Forms.DialogResult.Yes)) { try { Application.DoEvents(); Closing cleanup = new Closing(); cleanup.Show(); checkImageBR.Close(); checkImageFS.Close(); File.Delete(allImgFile); cleanup.Close(); } catch (Exception ex) { } } else { e.Cancel = true; } }
public void SaveTiffintoSingle(string outFile, EncoderValue compressEncoder) { //use for save image as single tiff int frame = 0; int startPos = 0; int imgLen = 0; byte[] recB = null; Closing exporting = new Closing(); bool frontImage = false; exporting.Text = "Exporting check images"; exporting.lblCleanup.Text = "exporting check images to tiff..."; exporting.Show(); this.Cursor = Cursors.WaitCursor; int reccnt = 0; string SingleTiffImagePath = string.Empty; try { foreach (x9Rec rec in x9Stuff) { if (rec.recType == "50" && rec.recData.Substring(31, 1) == "0") { frontImage = true; } else if (rec.recType == "50" && rec.recData.Substring(31, 1) == "1") { frontImage = false; } if (rec.recImage.Trim().Length > 0) { startPos = System.Convert.ToInt32(rec.recImage.Substring(0, rec.recImage.IndexOf(","))); imgLen = System.Convert.ToInt32(rec.recImage.Substring(rec.recImage.IndexOf(",") + 1)); checkImageBR.BaseStream.Seek(startPos, SeekOrigin.Begin); recB = new byte[imgLen + 1]; recB = checkImageBR.ReadBytes(imgLen); if (!Directory.Exists(outFile)) { Directory.CreateDirectory(outFile); } if (frontImage) { SingleTiffImagePath = frame + "F.tiff"; } else { SingleTiffImagePath = frame + "R.tiff"; frame += 1; } if (File.Exists(Path.Combine(outFile, SingleTiffImagePath))) { File.Delete(Path.Combine(outFile, SingleTiffImagePath)); } File.WriteAllBytes(Path.Combine(outFile, SingleTiffImagePath), recB); } reccnt += 1; exporting.pbCleanup.Value = (int)(reccnt / (double)x9Stuff.Count) * 100; Application.DoEvents(); } } catch (Exception ex) { exporting.TopMost = false; MessageBox.Show(ex.Message + " rec count=" + reccnt.ToString("###,###,###"), "Error Exporting", MessageBoxButtons.OK, MessageBoxIcon.Error); } exporting.Close(); this.Cursor = Cursors.Default; }
public void JoinTiffImages3(string outFile, EncoderValue compressEncoder) { //use the save encoder System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag; EncoderParameters ep = new EncoderParameters(2); ep.Param[0] = new EncoderParameter(enc, System.Convert.ToInt64(EncoderValue.MultiFrame)); ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, System.Convert.ToInt64(compressEncoder)); Bitmap pages = null; int frame = 0; ImageCodecInfo info = GetEncoderInfo("image/tiff"); Image cImg = null; int startPos = 0; int imgLen = 0; byte[] recB = null; Closing exporting = new Closing(); bool frontImage = false; exporting.Text = "Exporting check images"; exporting.lblCleanup.Text = "exporting check images to tiff..."; exporting.Show(); this.Cursor = Cursors.WaitCursor; int reccnt = 0; try { foreach (x9Rec rec in x9Stuff) { if (rec.recType == "50" && rec.recData.Substring(31, 1) == "0") { frontImage = true; } if (rec.recImage.Trim().Length > 0 && frontImage) { frontImage = false; startPos = System.Convert.ToInt32(rec.recImage.Substring(0, rec.recImage.IndexOf(","))); imgLen = System.Convert.ToInt32(rec.recImage.Substring(rec.recImage.IndexOf(",") + 1)); checkImageBR.BaseStream.Seek(startPos, SeekOrigin.Begin); recB = new byte[imgLen + 1]; recB = checkImageBR.ReadBytes(imgLen); Byte2Image(ref cImg, recB, 0); if (frame == 0) { pages = (Bitmap)cImg; //save the first frame pages.Save(outFile, info, ep); } else { //save the intermediate frames ep.Param[0] = new EncoderParameter(enc, System.Convert.ToInt64(EncoderValue.FrameDimensionPage)); pages.SaveAdd((Bitmap)cImg, ep); } frame += 1; } reccnt += 1; exporting.pbCleanup.Value = (int)(reccnt / (double)x9Stuff.Count) * 100; Application.DoEvents(); } } catch (Exception ex) { exporting.TopMost = false; MessageBox.Show(ex.Message + " rec count=" + reccnt.ToString("###,###,###"), "Error Exporting", MessageBoxButtons.OK, MessageBoxIcon.Error); } //flush and close. if (pages == null) { ep.Param[0] = new EncoderParameter(enc, System.Convert.ToInt64(EncoderValue.Flush)); pages.SaveAdd(ep); } exporting.Close(); this.Cursor = Cursors.Default; }