Convert tif file to gif list

Source: Internet
Author: User
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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.