转换图像的列表为GIF [英] Convert a List of Images to a GIf

查看:140
本文介绍了转换图像的列表为GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在试图从源图像条构造一个GIF图像,而我抓住以下异常错误:

System.Runtime.InteropServices.ExternalException(0X80004005 ):GDI +中发生genereric错误。在... ...线55. ...管线138

我使用的代码需要从控制台2用户输入文件路径,允许用户选择哪个图像被作为源,并确定为新的文件的路径。问题是,我不断收到异常错误,我可以没有任何意义了的:

I am currently trying to construct a GIF image from a source image strip, and I am catching the following exception error: System.Runtime.InteropServices.ExternalException (0x80004005): A genereric error occurred in GDI+. At ... line 55. At ... line 138. The code I am using takes 2 user inputted file paths from the console to allow the user to select which image is used as the source, and to define a path for the new file. The problem is that I keep getting exception errors that I can't make any sense out of:

public void ConvertToGif( string DestinationPath , Image myImage , int myFrames ) {
    Bitmap myBitmap = new Bitmap( myImage.Width / myFrames , myImage.Height );
    myBitmap.Save( DestinationPath , ImageFormat.Gif );

    Image myGIF = Image.FromFile( @DestinationPath );
    FrameDimension myDimensions = new FrameDimension( myGIF.FrameDimensionsList[ 0 ] );

    for( int i = 0; i < myFrames; i ++ ) {
        var DestRegion = new Rectangle( 0 , 0 , myGIF.Width , myGIF.Height );
        var SrceRegion = new Rectangle( myGIF.Width * i , 0 , myGIF.Width , myGIF.Height );
        Graphics GrDrw = Graphics.FromImage( myBitmap );
        GrDrw.DrawImage( myImage , DestRegion , SrceRegion , GraphicsUnit.Pixel );

        EncoderParameter encCompressionrParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW);
        EncoderParameter encQualityParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 0L);
        EncoderParameters myEncoderParameters = new EncoderParameters(2);
        myEncoderParameters.Param[0] = encCompressionrParameter;
        myEncoderParameters.Param[1] = encQualityParameter;
        myGIF.SaveAdd( myBitmap , myEncoderParameters ); /*Line 55*/
    }
}

的方法在这里是。创建一个空的位图,从图像条传送特定矩形帧位图,然后添加位图作为帧到GIF图像

The methodology here is to create an empty bitmap, transfer the specific rectangle frame from the image strip to the bitmap, then add the bitmap as a frame to the GIF image.

138行是这样的:

ConvertedGif =新GifConversion();
ConvertedGif.ConvertToGif(的DestinationPath,MYIMAGE,myFrames);

Line 138 is this: ConvertedGif = new GifConversion(); ConvertedGif.ConvertToGif( DestinationPath , myImage , myFrames );

推荐答案

不幸的是GDI +实现编码器为多框架的GIF都没有suppported你只能使用GDI +创建多帧的TIFF文件

Unfortunately GDI+ implementation of the encoders for multi-framed GIFs are not suppported you can only create multi-frame TIFFs files using GDI+.

请参阅这篇文章:的 http://www.universalthread.com/ViewPageArticle.aspx?ID=841

小从那里片段

不幸的是,这是不可能创建多帧,或使用GDIPLUS.DLL版本1图象编码器动画
GIFS。它可以用于将帧添加到多帧TIFF图像的SaveAdd方法
则与GIF编码器不
工作

Unfortunately, it is not possible to create Multi-frame or Animated GIFS using GdiPlus.dll version 1 image encoders. The SaveAdd method which can be used to add frames to a multi-frame TIFF image does not work with the GIF encoder.

您可以读取GIF文件的信息,但不允许您创建新框架等。

You can read information from GIF files but you are not permitted to create new frames etc.

有就是你可以从获得额外的元数据。净GDI +类,如帧延迟等。

There is additional metadata that you can get from the .Net GDI+ classes like the frame delay etc.

还有其他物品,包括www.asp.net网站援引GDI +不支持GIF写的

There is other articles including in www.asp.net site citing that GDI+ does not support writing GIF's

您可能会更好使用NGif它负责所有这一切的你。

You might be better off using NGif which takes care of all of that for you.

这个问题已经在这里问在计算器看看这个。

This question has already been asked here at stackoverflow have a look at this one.

C# - 从创建所选图像在ASP.net

另外这里是NGif - http://www.codeproject.com /文章/ 11505 / NGif动画,GIF编码器换NET

Also here is NGif - http://www.codeproject.com/Articles/11505/NGif-Animated-GIF-Encoder-for-NET

这篇关于转换图像的列表为GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆