Code
/// <Summary>
/// Convert the tif file to the GIF file list
/// </Summary>
/// <Param name = "FILENAME"> tif file to be converted </param>
/// <Returns> path of the converted GIF file </returns>
Public static ilist <string> converttiftogif (string filename)
{
Ilist <string> List = new list <string> ();
String DIC = appdomain. currentdomain. basedirectory + "\ tempgif \\";
If (! Directory. exists (DIC ))
{
Directory. createdirectory (DIC );
}
If (string. isnullorempty (filename ))
{
Throw new argumentexception ("The path of the converted tif file cannot be blank ");
}
Fileinfo file = new fileinfo (filename );
If (! File. exists)
{
Throw new filenotfoundexception ("The tif file to be converted does not exist ");
}
Image imgobj = image. fromfile (file. fullname );
// Image imgobj = imgobj2.getthumbnailimage (imgobj2.width/3*2, imgobj2.height/3*2, null, intptr. Zero); // image. fromfile (file. fullname );
Guid objguid = (guid) imgobj. framedimensionslist. getvalue (0 );
Framedimension objdimension = new framedimension (objguid );
Int totalimage = imgobj. getframecount (objdimension );
For (INT Index = 0; index <totalimage; index ++)
{
String gifpath = dic + file. Name. substring (0, file. Name. lastindexof ('.') + "_" + index + ". GIF ";
If (file. exists (gifpath ))
{
File. Delete (gifpath );
}
// Encoderparameter en = new encoderparameter ();
Imgobj. selectactiveframe (objdimension, index );
Imgobj. Save (gifpath, imageformat. GIF );
Fileinfo item = new fileinfo (gifpath );
List. Add ("tempgif \" + item. Name );
}
Return list;
}