net]如何将多页的TIF图片分割成多个单页的TIF文件

net]如何将多页的TIF图片分割成多个单页的TIF文件
[ 2006-12-07 16:16:04 | 作者: Bin ]
: | |
TIF图片格式本是网上有许多资料介绍。
这两天找了一些资料,用做切割TIF图片用的。

功能:把多页的TIF图片切割为单页的TIF多文件!

下面是C#代码(已封装):

1 using System;  
2 using System.IO;  
3 using System.Drawing;  
4 using System.Collections;  
5 using System.Drawing.Imaging;  
6  
7 namespace SampleProject.Components {  
8     class ImageSplit {  
9         private FileInfo _imageFile;  
10         private ArrayList _imagesName = new ArrayList();  
11  
12         public ArrayList ImagesName {  
13             get { return _imagesName; }  
14         }  
15  
16         public ImageSplit( FileInfo imageFile, string IncisionDir ) {  
17             this._imageFile = imageFile;  
18             Split( IncisionDir );  
19         }  
20  
21         ///   
22         /// Split image to folder  
23         ///   
24         ///   
25         protected void Split( string IncisionDir ) {  
26             try {  
27                 Image img = Image.FromFile( _imageFile.FullName );  
28                 Guid guid = (Guid)img.FrameDimensionsList.GetValue( 0 );  
29                 FrameDimension dimension = new FrameDimension( guid );  
30                 int totalPage = img.GetFrameCount( dimension );  
31  
32                 for ( int i = 0;i < totalPage;i++ ) {  
33                     img.SelectActiveFrame( dimension, i );  
34                     img.Save( IncisionDir + "//" + _imageFile.Name.Substring( 0, _imageFile.Name.LastIndexOf( '.' ) ) + "_" + i + ".tif", System.Drawing.Imaging.ImageFormat.Tiff );  
35                     _imagesName.Add( _imageFile.Name.Substring( 0, _imageFile.Name.LastIndexOf( '.' ) ) + "_" + i + ".tif" );  
36                 }  
37  
38                 img.Dispose();  
39             }  
40             catch {  
41                 return;  
42             }  
43         }  
44  
45         ///   
46         /// Move image to backup folder  
47         ///   
48         ///   
49         public void MoveImage( string backupDir ) {  
50  
51             string strDir = backupDir + "//" + DateTime.Now.ToShortDateString();  
52  
53             if ( !Directory.Exists( strDir ) ) {  
54                 Directory.CreateDirectory( strDir );  
55             }  
56  
57             if ( File.Exists( strDir + "//" + _imageFile.Name ) ) {  
58                 File.Delete( strDir + "//" + _imageFile.Name );  
59             }  
60  
61             _imageFile.MoveTo( strDir + "//" + _imageFile.Name );  
62         }  
63     }  
64 }  
 view plain | print | copy to clipboard | ?

调用方法:

1 System.IO.DirectoryInfo sourceFolder = new DirectoryInfo( IMAGE_SOURCE_FOLDER );  
2 FileInfo[] imageFile = sourceFolder.GetFiles();  
3  
4 for ( int i = 0;i < imageFile.Length;i++ ) {  
5     Components.ImageSplit split = new Components.ImageSplit( imageFile[i], INCISION_FOLDER );  
6     split.MoveImage( IMAGE_MOVETO_FOLDER );  
7 }   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值