概述
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 }
最后
以上就是畅快音响为你收集整理的net]如何将多页的TIF图片分割成多个单页的TIF文件的全部内容,希望文章能够帮你解决net]如何将多页的TIF图片分割成多个单页的TIF文件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复