Flash文件在网页上传怎么生成缩略图?Asp.net C#,求C#代码
图片上传后,可以用C#怎么生成一张小的缩略图那Flash呢,这个怎么办,在预览时用的是ActiveX控件object;Flash文件在网页上传怎么生成缩略图?Asp.ne...
图片上传后,可以用C#怎么生成一张小的缩略图 那Flash呢,这个怎么办,在预览时用的是ActiveX控件object; Flash文件在网页上传怎么生成缩略图?Asp.net C#,求C#代码
展开
3个回答
2011-08-22
展开全部
/// <summary>
/// 为图片生成缩略图
/// </summary>
/// <param name="phyPath">原图片的路径</param>
/// <param name="width">缩略图宽</param>
/// <param name="height">缩略图高</param>
/// <returns></returns>
public static string GetThumbnail(string phyPath, int width, int height)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(phyPath);
int orignWidth = image.Width; //原图尺寸
int orignHeight = image.Height;
float toWidth = (float)width; //缩略图目标尺寸
float toHeight = (float)height;
float radio = (float)orignWidth / (float)orignHeight; //宽高比例
if (orignWidth >= orignHeight)
{ //宽度不变
toHeight = toWidth / radio;
}
else
{ //高度不变
toWidth = toHeight * radio;
}
System.Drawing.Image thumbImage = image.GetThumbnailImage(Convert.ToInt32(toWidth), Convert.ToInt32(toHeight), null, IntPtr.Zero);
string folder = Path.GetDirectoryName(phyPath);
string fileName = "\\s_" + Path.GetFileName(phyPath);
string savePath = folder + fileName;
try
{
thumbImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
image.Dispose();
thumbImage.Dispose();
}
return savePath;
}
试试这个
/// 为图片生成缩略图
/// </summary>
/// <param name="phyPath">原图片的路径</param>
/// <param name="width">缩略图宽</param>
/// <param name="height">缩略图高</param>
/// <returns></returns>
public static string GetThumbnail(string phyPath, int width, int height)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(phyPath);
int orignWidth = image.Width; //原图尺寸
int orignHeight = image.Height;
float toWidth = (float)width; //缩略图目标尺寸
float toHeight = (float)height;
float radio = (float)orignWidth / (float)orignHeight; //宽高比例
if (orignWidth >= orignHeight)
{ //宽度不变
toHeight = toWidth / radio;
}
else
{ //高度不变
toWidth = toHeight * radio;
}
System.Drawing.Image thumbImage = image.GetThumbnailImage(Convert.ToInt32(toWidth), Convert.ToInt32(toHeight), null, IntPtr.Zero);
string folder = Path.GetDirectoryName(phyPath);
string fileName = "\\s_" + Path.GetFileName(phyPath);
string savePath = folder + fileName;
try
{
thumbImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
image.Dispose();
thumbImage.Dispose();
}
return savePath;
}
试试这个
展开全部
专门有ActiveX控件的,注册到系统后可以通过C#调用。我3年前做过这个功能,很好用。
用的是SWFToImage,下载地址:http://bytescout.com/download/download_freeware.html
直接下载地址:http://bytescout.com/files/SWFToImage.exe.
特别提示:在电脑端需要同时装FLASH的ACTIVEX控件(而不是FLASHPLAYER)。否则会报COM组件没注册
代码如下:
public class FlashCapture
{
/// <summary>
/// 用户自上传的文件预览
/// </summary>
/// <param name="FlashFilePath">文件路径</param>
public static void FilePreviewCapture(string FlashFilePath)
{
if (!System.IO.File.Exists(FlashFilePath + ".swf"))
{
System.IO.File.Copy(FlashFilePath, FlashFilePath + ".swf");
}
SWFToImage.SWFToImageObjectClass swf = new SWFToImage.SWFToImageObjectClass();
swf.InitLibrary("demo", "demo");
swf.InputSWFFileName = FlashFilePath;
swf.ImageOutputType = SWFToImage.TImageOutputType.iotJPG;
swf.Execute_Begin();
SWFHeaderInfo s = new SWFHeaderInfo(FlashFilePath);
swf.ImageWidth = (int)s.xMax;
swf.ImageHeight = (int)s.yMax;
Random rnd = new Random();
swf.FrameIndex = rnd.Next(swf.FramesCount);
swf.Execute_GetImage();
swf.SaveToFile(FlashFilePath + ".jpg");
swf.Execute_End();
if (System.IO.File.Exists(FlashFilePath + ".swf"))
{
System.IO.File.Delete(FlashFilePath + ".swf");
}
}
/// <summary>
/// 自主更新的FLASH的截图部分
/// </summary>
/// <param name="FlashFilePath">FLASH文件路径</param>
/// <param name="FileBaseName">预览图路径</param>
public static void FilePreviewCapture(string FlashFilePath,string PicFilePath)
{
if (System.IO.File.Exists(FlashFilePath))
{
SWFToImage.SWFToImageObjectClass swf = new SWFToImage.SWFToImageObjectClass();
swf.InitLibrary("demo", "demo");
swf.InputSWFFileName = FlashFilePath;
swf.ImageOutputType = SWFToImage.TImageOutputType.iotJPG;
swf.Execute_Begin();
SWFHeaderInfo s = new SWFHeaderInfo(FlashFilePath);
swf.ImageWidth = (int)s.xMax;
swf.ImageHeight = (int)s.yMax;
Random rnd = new Random();
swf.FrameIndex = rnd.Next(swf.FramesCount);
swf.Execute_GetImage();
swf.SaveToFile(PicFilePath);
swf.Execute_End();
}
}
}
其中,SWFHeaderInfo是获取FLASH头信息的类,因为你需要知道截图之后图片的宽高信息。代码下载地址:
http://osflash.org/swfheaderinfo
用的是SWFToImage,下载地址:http://bytescout.com/download/download_freeware.html
直接下载地址:http://bytescout.com/files/SWFToImage.exe.
特别提示:在电脑端需要同时装FLASH的ACTIVEX控件(而不是FLASHPLAYER)。否则会报COM组件没注册
代码如下:
public class FlashCapture
{
/// <summary>
/// 用户自上传的文件预览
/// </summary>
/// <param name="FlashFilePath">文件路径</param>
public static void FilePreviewCapture(string FlashFilePath)
{
if (!System.IO.File.Exists(FlashFilePath + ".swf"))
{
System.IO.File.Copy(FlashFilePath, FlashFilePath + ".swf");
}
SWFToImage.SWFToImageObjectClass swf = new SWFToImage.SWFToImageObjectClass();
swf.InitLibrary("demo", "demo");
swf.InputSWFFileName = FlashFilePath;
swf.ImageOutputType = SWFToImage.TImageOutputType.iotJPG;
swf.Execute_Begin();
SWFHeaderInfo s = new SWFHeaderInfo(FlashFilePath);
swf.ImageWidth = (int)s.xMax;
swf.ImageHeight = (int)s.yMax;
Random rnd = new Random();
swf.FrameIndex = rnd.Next(swf.FramesCount);
swf.Execute_GetImage();
swf.SaveToFile(FlashFilePath + ".jpg");
swf.Execute_End();
if (System.IO.File.Exists(FlashFilePath + ".swf"))
{
System.IO.File.Delete(FlashFilePath + ".swf");
}
}
/// <summary>
/// 自主更新的FLASH的截图部分
/// </summary>
/// <param name="FlashFilePath">FLASH文件路径</param>
/// <param name="FileBaseName">预览图路径</param>
public static void FilePreviewCapture(string FlashFilePath,string PicFilePath)
{
if (System.IO.File.Exists(FlashFilePath))
{
SWFToImage.SWFToImageObjectClass swf = new SWFToImage.SWFToImageObjectClass();
swf.InitLibrary("demo", "demo");
swf.InputSWFFileName = FlashFilePath;
swf.ImageOutputType = SWFToImage.TImageOutputType.iotJPG;
swf.Execute_Begin();
SWFHeaderInfo s = new SWFHeaderInfo(FlashFilePath);
swf.ImageWidth = (int)s.xMax;
swf.ImageHeight = (int)s.yMax;
Random rnd = new Random();
swf.FrameIndex = rnd.Next(swf.FramesCount);
swf.Execute_GetImage();
swf.SaveToFile(PicFilePath);
swf.Execute_End();
}
}
}
其中,SWFHeaderInfo是获取FLASH头信息的类,因为你需要知道截图之后图片的宽高信息。代码下载地址:
http://osflash.org/swfheaderinfo
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-08-23
展开全部
fdsafdsfdasfasf
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询