您好:
保存图片是报错,麻烦您给看下:
保存代码如下:
- private void 保存本地ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- RasterImage image = null;
- using (SaveFileDialog sfd = new SaveFileDialog())
- {
- sfd.Filter = "扫描图像文件(*.pdf)|*.pdf|扫描图像文件(*.tif)|*.tif;";
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string fileName = sfd.FileName;
- string ext = fileName.Substring(fileName.LastIndexOf(".") + 1);
- if (Directory.Exists(_tempFilePath))
- {
- DirectoryInfo dir = new DirectoryInfo(_tempFilePath);
- FileInfo[] files = dir.GetFiles();
- SortAsFileName(ref files);
- if (files.Count() > 0)
- {
- for (int i = 0; i < files.Count(); i++)
- {
- RasterImage tempImage = _codecs.Load(files[i].FullName, 1);
- if (image == null)
- image = tempImage;
- else
- image.AddPage(tempImage);
- }
- }
- }
- if (ext == "pdf")
- {
- _codecs.Save(image, fileName, RasterImageFormat.RasPdf, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
- image.Dispose();
- }
- if (ext == "tif")
- {
- _codecs.Save(image, fileName, RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
- image.Dispose();
- }
- }
- }
- }
复制代码
保存为pdf时报错,保存为tif时没事
测试图片
|