显示Flash时控制其的宽度与高度
Flash在网页显示时,如果不指定其正确的宽度或高度或是按其宽高一定的比例,会变形。
你可以从下面地址参考到怎样取得Flash的宽度或是高度一些信息。http://www.codeproject.com/KB/graphics/ReaderSWFHeader.aspx
为了更好了解,Insus.NET在下面写了一个swf类别(代码部分)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public Swf(int Width, int Height, int ThumbnailSize, string File)
{
this._Width = Width;
this._Height = Height;
this._ThumbnailSize = ThumbnailSize;
this._File = File;
}
public string Player()
{
int f_Width;
int f_Height;
if (_ThumbnailSize > 0) //如果指定Flash缩略显示
{
//如果Flash的宽度与高度都小于指定缩略尺寸
if (_Width < _ThumbnailSize && _Height < _ThumbnailSize)
{
f_Width = _Width; //等于原来的宽度
f_Height = _Height;//等于原来的高度
}
//如果宽度大于高度
else if (_Width > _Height)
{
f_Width = _ThumbnailSize;
f_Height = _Height * _ThumbnailSize / _Height;
}
//如果高度大于宽度
else
{
f_Width = _Width * _ThumbnailSize / _Height;
f_Height = _ThumbnailSize;
}
}
else
{
f_Width = _Width;
f_Height = _Height;
}
return @"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'width=" + f_Width + " height=" + f_Height + ">"
+ @" <param name='movie' value=" + _File + ">"
+ @" <param name='quality' value='high'>"
+ @"<embed src=" + _File + " quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=" + f_Width + " height=" + f_Height + "></embed>"
+ @" </object>";
}
{
this._Width = Width;
this._Height = Height;
this._ThumbnailSize = ThumbnailSize;
this._File = File;
}
public string Player()
{
int f_Width;
int f_Height;
if (_ThumbnailSize > 0) //如果指定Flash缩略显示
{
//如果Flash的宽度与高度都小于指定缩略尺寸
if (_Width < _ThumbnailSize && _Height < _ThumbnailSize)
{
f_Width = _Width; //等于原来的宽度
f_Height = _Height;//等于原来的高度
}
//如果宽度大于高度
else if (_Width > _Height)
{
f_Width = _ThumbnailSize;
f_Height = _Height * _ThumbnailSize / _Height;
}
//如果高度大于宽度
else
{
f_Width = _Width * _ThumbnailSize / _Height;
f_Height = _ThumbnailSize;
}
}
else
{
f_Width = _Width;
f_Height = _Height;
}
return @"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'width=" + f_Width + " height=" + f_Height + ">"
+ @" <param name='movie' value=" + _File + ">"
+ @" <param name='quality' value='high'>"
+ @"<embed src=" + _File + " quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=" + f_Width + " height=" + f_Height + "></embed>"
+ @" </object>";
}
xxx.aspx使用:
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
xxx.aspx.cs:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//codeproject下载的Flash类别,Insus.NET曾经修改过,改为FlashInfo,基本是一样的,只不过添加一些自己的属性。
FlashInfo objFlashInfo = new FlashInfo(Server.MapPath(file));
Swf objSwf = new Swf(objFlashInfo.Width, objFlashInfo.Height,400, file);
this.Literal1.Text = objSwf.Player();
FlashInfo objFlashInfo = new FlashInfo(Server.MapPath(file));
Swf objSwf = new Swf(objFlashInfo.Width, objFlashInfo.Height,400, file);
this.Literal1.Text = objSwf.Player();