您好:
我现在想将导入图片功能中的图片暂存到本地,导入功能代码如下:
- private void ImportImage(object sender, EventArgs e)
- {
- if (Directory.Exists(_tempFilePath))
- {
- Directory.Delete(_tempFilePath, true);
- }
- CodecsImageInfo info = new CodecsImageInfo();
- string fileName = string.Empty;
- using (OpenFileDialog dlg = new OpenFileDialog())
- {
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- imageViewer1.Items.Clear();
- info = _codecs.GetInformation(dlg.FileName, true);
- fileName = dlg.FileName;
- }
- }
- LeadSize thumbSize = imageViewer1.ItemSize;
- using (WaitCursor waitCursor = new WaitCursor())
- {
- imageViewer1.BeginUpdate();
- if (info.TotalPages > 0)
- {
- for (int i = 1; i < info.TotalPages + 1; i++)
- {
- RasterImage image = _codecs.Load(fileName, i);
- string fileNameTemp = _tempFilePath + (i - 1).ToString() + ".tif";
- if (!Directory.Exists(_tempFilePath))
- {
- Directory.CreateDirectory(_tempFilePath);
- }
- _codecs.Save(image, fileNameTemp, RasterImageFormat.Tif, image.BitsPerPixel);
- RasterImage tnImage = image.CreateThumbnail(thumbSize.Width, thumbSize.Height, image.BitsPerPixel, RasterViewPerspective.TopLeft, RasterSizeFlags.Bicubic);
- ImageViewerItem item = new ImageViewerItem();
- item.Image = tnImage;
- item.Text = string.Format("第{0}页", i);
- item.PageNumber = 1;
- imageViewer1.Items.Insert(i - 1, item);
- //image.Dispose();
- //tnImage.Dispose();
- }
- imageViewer1.Items[0].IsSelected = true;
- _scanCount = info.TotalPages - 1;
- }
- imageViewer1.EndUpdate();
- }
- }
复制代码 如果导入的文件里面的图片太多(200页以上)程序会出现假死的状态,这个有什么解决方法吗,是要用多线程来处理吗,不知道怎么做了,麻烦您指导下
|
|