swf截图

public abstract class Swf2Imgae
{
	public Swf2Imgae()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//

	}
	private static readonly int _defaultImgType = (int)SWFToImage.TImageOutputType.iotJPG;
	private static readonly int _defaultWidth = WebConfiguration.ConverterSetting.GetThumbSize()[0];
	private static readonly int _defaultHeight = WebConfiguration.ConverterSetting.GetThumbSize()[1];
	/// <summary>
	/// 截取swf缩略图
	/// </summary>
	/// <param name="swfPath">输入swf路径</param>
	/// <param name="outImgPath">输出图片路径</param>
	/// <param name="imgType">iotBMP = 0,iotJPG = 1,iotGIF = 2,iotPNG = 3,</param>
	/// <param name="width">设置生成图片的宽度</param>
	/// <param name="height">设置生成图片的高度</param>
	/// <returns></returns>
	public static string SWF2Image(string swfPath,string outImgPath,int width,int height)
	{
		try
		{
			SWFToImage.TImageOutputType imgType = SWFToImage.TImageOutputType.iotJPG; ;
			if (!System.IO.File.Exists(swfPath))
			{
				return "ERROR:no find the swf file,invalid swf path";
			}
			string imgTypeStr = System.IO.Path.GetExtension(outImgPath);
			switch (imgTypeStr.ToLower())
			{
			case ".bmp":
					imgType = SWFToImage.TImageOutputType.iotBMP;
				break;
			case ".gif":
				imgType = SWFToImage.TImageOutputType.iotGIF;
				break;
			case ".jpg":
				imgType = SWFToImage.TImageOutputType.iotJPG;
				break;
			case ".png":
				imgType = SWFToImage.TImageOutputType.iotPNG;
				break;
			}
			string imgDir = System.IO.Path.GetDirectoryName(outImgPath);
			if (!System.IO.Directory.Exists(imgDir))
			{
				System.IO.Directory.CreateDirectory(imgDir);
			}
			SWFToImage.SWFToImageObjectClass c = new SWFToImage.SWFToImageObjectClass();
			c.ImageHeight = height;
			c.ImageWidth = width;
			c.JPEGQuality = 127;
			c.InputSWFFileName = swfPath;
			c.ImageOutputType = imgType;//SWFToImage.TImageOutputType.iotJPG;
			c.Execute();
            
			bool result = c.SaveToFile(outImgPath);
			if (!result)
			{
				return "ERROR:convert fail";
			}
			if (System.IO.File.Exists(outImgPath))
			{
				return outImgPath;
			}
		}
		catch (System.Exception ex)
		{
			return "ERROR:" + ex.Message;
		}
		
		return null;
	}
	/// <summary>
	/// 截取swf缩略图,默认宽高为400:300,默认格式为jpg
	/// </summary>
	/// <param name="swfPath">输入swf路径</param>
	/// <param name="outImgPath">输出图片路径</param>
	/// <returns></returns>
	public static string SWF2Image(string swfPath, string outImgPath)
	{
		return SWF2Image(swfPath, outImgPath, _defaultWidth, _defaultHeight);
	}
    public static object SWF2Image(string swfPath)
    {
        SWFToImage.SWFToImageObjectClass c = new SWFToImage.SWFToImageObjectClass();
        c.ImageHeight = _defaultHeight;
        c.ImageWidth = _defaultWidth;
        c.JPEGQuality = 127;
        c.InputSWFFileName = swfPath;
        c.ImageOutputType =SWFToImage.TImageOutputType.iotJPG;
        c.Execute();
        return c.BinaryImage;
        
    }
    /// <summary>
    /// 截取swf缩略图,默认宽高为400:300,默认格式为jpg
    /// </summary>
    /// <param name="swfPath">输入swf路径</param>
    /// <param name="outImgPath">输出图片路径</param>
    /// <returns></returns>
    public static void SWF2Image(object o)
    {
        SWF2ImageParams4 Values=null;
        SWF2ImageParams2 Values2 = null;
        try
        {
             Values = (SWF2ImageParams4)o;
            if (Values==null)
            {
                return;
            }
            SWF2Image(Values.SwfPath, Values.ImgPath, Values.Width, Values.Height);
        }
        catch (System.Exception ex)
        {
            Values2 = (SWF2ImageParams2)o;
            if (Values2 == null)
            {
                return;
            }
            SWF2Image(Values2.SwfPath, Values2.ImgPath, _defaultWidth, _defaultHeight);
        }
        
        
    }
    /// <summary>
    /// 供SWF2Image 重载(4参数)SwfPath;ImgPath,Width,Height使用
    /// </summary>
    public class SWF2ImageParams4
    {
        public string SwfPath;
        public string ImgPath;
        public int Width;
        public int Height;
    }
    /// <summary>
    /// 供SWF2Image 重载(2参数)SwfPath;ImgPath;使用
    /// </summary>
    public class SWF2ImageParams2
    {
        public string SwfPath;
        public string ImgPath;
    }
}

  

原文地址:https://www.cnblogs.com/jtans/p/2758717.html