- private void 导入ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- CodecsImageInfo info = new CodecsImageInfo();
- string fileName = string.Empty;
- int firstPage = 1;
- int lastPage = 1;
- int pageIndex = 0;
- using (OpenFileDialog dlg = new OpenFileDialog())
- {
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- imageViewer1.Items.Clear();
- _ocrDocument.Pages.Clear();
- info = _codecs.GetInformation(dlg.FileName, true);
- fileName = dlg.FileName;
- }
- }
- if (!string.IsNullOrEmpty(fileName))
- {
- lastPage = info.TotalPages;
- using (WaitCursor waitCursor = new WaitCursor())
- {
- _ocrDocument.Pages.InsertPages(pageIndex, fileName, firstPage, lastPage, null);//代码运行到这里就报错了
- imageViewer1.BeginUpdate();
- if (_ocrDocument != null)
- {
- LeadSize thumbSize = imageViewer1.ItemSize;
- int index = pageIndex;
- for (int i = 0; i < lastPage; i++)
- {
- IOcrPage ocrPage = _ocrDocument.Pages[index];
- RasterImage image = ocrPage.CreateThumbnail(thumbSize.Width, thumbSize.Height);
- ImageViewerItem item = new ImageViewerItem();
- item.Image = image;
- item.Text = string.Format("第{0}页", i + 1);
- item.PageNumber = 1;
- imageViewer1.Items.Insert(index, item);
- index++;
- }
- imageViewer1.Items[0].IsSelected = true;
- }
- imageViewer1.EndUpdate();
- }
- fileName = string.Empty;
- }
- }
复制代码
|