如何用java知道swf文件的原始大小(宽度和高度)?
有没有办法用java知道swf文件的原始宽度和高度?
int width, height;
// my stream contains an image or a swf file
InputStream stream = file.getInputStream();
// mediaType has been set with the help of file extension
switch (mediaType)
{
case IMAGE:
BufferedImage img = ImageIO.read(stream);
width = img.getWidth();
height = img.getHeight();
break;
case FLASH:
// what is the code here ?
break;
}
Is there a way to know the original width and height of an swf file with java ?
int width, height;
// my stream contains an image or a swf file
InputStream stream = file.getInputStream();
// mediaType has been set with the help of file extension
switch (mediaType)
{
case IMAGE:
BufferedImage img = ImageIO.read(stream);
width = img.getWidth();
height = img.getHeight();
break;
case FLASH:
// what is the code here ?
break;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我查看了 brooksandrus 源代码,有些不知所措,所以我编写了自己的“一个顶级类”解决方案。我意识到这篇文章很长,但不知道如何以其他方式发布它。
注意:我用 HTML 等效项对尖括号进行了全局替换,以使其正确显示。如果您剪切并粘贴它,希望您不必恢复该更改。
I looked at the brooksandrus source, and was somewhat underwhelmed, so I wrote my own "one top-level class" solution. I realize this makes a long-ish post, but didn't know how to otherwise publish it.
Note: I did a global replacement of angle-brackets with their HTML-equivalents to get this to display properly. If you cut-and-paste it, hopefully you won't have to revert that change.
嗯,获取 Flash 文件的宽度和高度对我来说也很有趣。
不过,到目前为止我还没有找到一种简单的方法来做到这一点。
经过短暂的谷歌搜索后,我偶然发现了这个:
http://www.brooksandrus.com/blog/2006/08/11/lightweight-swf-header-reader-java-ii/
这是一个允许您解析 Flash 文件头的库,但是它已经有好几年的历史了,评论表明它在 Flash 7 以上版本中失败(这将使它现在几乎毫无用处)。但也许稍微调整一下就可以了。
但我不得不说,我没有尝试过那个库。
希望有帮助
Well, getting the width and height of a flash file is also interesting for me.
I haven't found an easy way to do this up to now, though.
After a short google search I stumbled upon this:
http://www.brooksandrus.com/blog/2006/08/11/lightweight-swf-header-reader-java-ii/
It's a library that allows you to parse a flash file header, but it's several years old and the comments suggest that it fails for flash 7 upwards (which would render it near useless now). But perhaps with a bit tweaking it would work.
I have to say, though, that I didn't try that library.
Hope that helps