找回密码
 立即注册

QQ登录

只需一步,快速开始

mosquito

初级会员

24

主题

138

帖子

328

积分

初级会员

积分
328

[已处理] 导入图片是报错

mosquito
初级会员   /  发表于:2016-3-22 11:07  /   查看:8152  /  回复:19
您好我在导入一个pdf文件时文件页数有260多页在执行代码_ocrDocument.Pages.InsertPages(pageIndex, fileName, firstPage, lastPage, null);这句代码时报错错误信息是Not enough memory available,能给我看看什么原因造成的吗是我文件太大了?

19 个回复

倒序浏览
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-3-22 14:44:55
沙发
根据信息来看,是内存不够了。

你的操作系统是32位的还是64位的?内存多少?
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-22 14:49:45
板凳
我这个电脑是64位win7 内存是8G的这都不够用吗
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-22 14:51:38
地板
_ocrDocument.Pages.InsertPages(pageIndex, fileName, firstPage, lastPage, null);还是说我直接这样写的话会有问题,有没有优化方案
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-3-22 15:01:20
5#
mosquito 发表于 2016-3-22 14:51
_ocrDocument.Pages.InsertPages(pageIndex, fileName, firstPage, lastPage, null);还是说我直接这样写的 ...

准确的说就是不够用。
因为你将PDF的每一页都变为图片了,而图片是无法压缩的,占用内存的大小可以计算。
计算方法为:图片长*宽*颜色位深*/8 bit
我使用一张A4幅面的彩色PDF扫描文档举例子:
2479 x 3508 x 24 bits / 8 bits = 26,088,996 字节或者26 MB 每页。
如果你需要加载200张的话,那就是260x 26 = 6760MB,约为6.5GB内存占用。
操作系统占用内存为1GB左右,其他程序占用1GB,全部可用内存最多为6GB,而你需要加载超过6.5GB的图片,内存就出现了不够用的情况。
我的建议是,如果是黑白文档扫描,请将每一页图片都变为1bit黑白图,这样占用内存会减少24倍。
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-22 15:11:48
6#
我导入的pdf文件总共大小才41.9 MB,会是您说的占用那么多的内存吗
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-3-22 15:22:33
7#
mosquito 发表于 2016-3-22 15:11
我导入的pdf文件总共大小才41.9 MB,会是您说的占用那么多的内存吗

转换为图片的话,就是这么大。
能否将你打开PDF,然后导入的代码发上来,我帮你看看是否使用上出了问题。
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-22 15:31:30
8#
  1. private void 导入ToolStripMenuItem_Click(object sender, EventArgs e)
  2.         {
  3.             CodecsImageInfo info = new CodecsImageInfo();
  4.             string fileName = string.Empty;
  5.             int firstPage = 1;
  6.             int lastPage = 1;
  7.             int pageIndex = 0;
  8.             using (OpenFileDialog dlg = new OpenFileDialog())
  9.             {
  10.                 if (dlg.ShowDialog() == DialogResult.OK)
  11.                 {
  12.                     imageViewer1.Items.Clear();
  13.                     _ocrDocument.Pages.Clear();
  14.                     info = _codecs.GetInformation(dlg.FileName, true);
  15.                     fileName = dlg.FileName;
  16.                 }
  17.             }

  18.             if (!string.IsNullOrEmpty(fileName))
  19.             {
  20.                 lastPage = info.TotalPages;
  21.                 using (WaitCursor waitCursor = new WaitCursor())
  22.                 {
  23.                     _ocrDocument.Pages.InsertPages(pageIndex, fileName, firstPage, lastPage, null);//代码运行到这里就报错了
  24.                     imageViewer1.BeginUpdate();
  25.                     if (_ocrDocument != null)
  26.                     {
  27.                         LeadSize thumbSize = imageViewer1.ItemSize;
  28.                         int index = pageIndex;
  29.                         for (int i = 0; i < lastPage; i++)
  30.                         {
  31.                             IOcrPage ocrPage = _ocrDocument.Pages[index];
  32.                             RasterImage image = ocrPage.CreateThumbnail(thumbSize.Width, thumbSize.Height);
  33.                             ImageViewerItem item = new ImageViewerItem();
  34.                             item.Image = image;
  35.                             item.Text = string.Format("第{0}页", i + 1);
  36.                             item.PageNumber = 1;
  37.                             imageViewer1.Items.Insert(index, item);
  38.                             index++;
  39.                         }
  40.                         imageViewer1.Items[0].IsSelected = true;
  41.                     }
  42.                     imageViewer1.EndUpdate();
  43.                 }
  44.                 fileName = string.Empty;
  45.             }
  46.         }
复制代码


回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-22 15:32:53
9#
我感觉是不是还是我写的有问题,我刚刚试了下C:\LEADTOOLS 19\Shortcuts\OCR - MICR - ICR - OMR\.NET Class Libraries\Main OCR Demo里面的OCR Multi-Engine 32-bit Demo这个例子是可以导入的
回复 使用道具 举报
mosquito
初级会员   /  发表于:2016-3-22 16:08:51
10#
您说的这个将每一页图片都变为1bit黑白图,转换方法能给我说下吗 谢谢了
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部