Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java程序分享区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
作者 获得Flash首选尺寸的方法
Jove



CJSDN高级会员


发贴: 1228
于 2004-02-22 14:23 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
swf也就是Flash, 和GIF/JPEG等图片格式一样,
页面中最好以他首选尺寸显示,至少应该维持他的长宽比例

下面这段代码便是分析swf文件得到其首选尺寸
或许这对本论坛,或是其他正在做web项目的朋友有帮助

import java.awt.Dimension;
import java.io.*;

/**
* @author Jove
*/
public final class SwfUtils {

  /**
   * 得到一个SWF文件的首选尺寸.
   * 算法介绍:<br>
   * 感谢avie提供swf格式的支持
   * 从第9个字节起读5 bits,设值为n;
   * 越过n bits,读n bits,设值为x;
   * 再跳过n bits,读取n bits,设值为y。
   * swf的宽度和高度依次为x/20和y/20像素
   */
  public static Dimension getPreferredSize(InputStream is)
    throws IOException {
    is.skip(8);
    byte[] head = new byte[9];
    is.read(head);
    head = toBitArray(head);
    int n = (int) readBit(head, 0, 5);
    long x = readBit(head, 5 + n, n);
    long y = readBit(head, 5 + n * 3, n);
    return new Dimension((int) (x / 20), (int) (y / 20));
  }

  /**
   * 从data的from位开始,依次读出length个bit
   * @param data 数组的每一个元素表示一个bit
   * @param from 起始位置
   * @param length 读bit的个数
   * @return 对应的long型值
   * @see #toBitArray
   */
  private static long readBit(byte[] data, int from, int length) {
    long rv = 0;
    for (int i = 0; i < length; i++) {
      rv += data[from + i] << (length - i - 1);
    }
    return rv;
  }

  /**
   * 把byte数组转为bit数组
   * @param data 数据流
   * @return 对应的bit数组,长度位data.length*8
   */
  private static byte[] toBitArray(byte[] data) {
    byte[] rv = new byte[data.length * 8];
    for (int i = 0; i < data.length; i++) {
      rv[i * 8] = (byte) ((data[i] & 0x80) > 0 ? 1 : 0);
      rv[i * 8 + 1] = (byte) ((data[i] & 0x40) > 0 ? 1 : 0);
      rv[i * 8 + 2] = (byte) ((data[i] & 0x20) > 0 ? 1 : 0);
      rv[i * 8 + 3] = (byte) ((data[i] & 0x10) > 0 ? 1 : 0);
      rv[i * 8 + 4] = (byte) ((data[i] & 0x08) > 0 ? 1 : 0);
      rv[i * 8 + 5] = (byte) ((data[i] & 0x04) > 0 ? 1 : 0);
      rv[i * 8 + 6] = (byte) ((data[i] & 0x02) > 0 ? 1 : 0);
      rv[i * 8 + 7] = (byte) ((data[i] & 0x01) > 0 ? 1 : 0);
    }
    return rv;
  }
}



作者 Re:获得Flash首选尺寸的方法 [Re:Jove]
Jove



CJSDN高级会员


发贴: 1228
于 2004-02-22 19:47 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我那个朋友avie自己用C实现的版本
#include <stdio.h>
typedef unsigned char s;
#define a b(&c,d),printf("%d ",b(&c,d)/20)
int b(s**p,int c){int b=0,d;static s t,l;
for(;c;c-=d){if(!l)t=*(*p)++,l=8;if((d=c)>l)d=l;
b<<=d;b|=(t>>(l-=d))&((1<<d)-1);}return b;}
void main(int d,char**v){FILE *f;s _[25],*c=_+8;
if(d>1&&(f=fopen(v[1],"rb")))fread(_,1,25,f),
fclose(f),d=b(&c,5),a,a;}

用法:exename swfname



作者 Re:获得Flash首选尺寸的方法 [Re:Jove]
rainman

阿熊

元老


发贴: 5644
于 2004-02-24 11:49 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Jute也支持swf的读取啊。flash5-flash mx统统支持。



作者 Re:获得Flash首选尺寸的方法 [Re:rainman]
Jove



CJSDN高级会员


发贴: 1228
于 2004-02-24 12:02 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这是一个100*100象素的swf, 使用Flash MX 2004制作



作者 Re:获得Flash首选尺寸的方法 [Re:Jove]
menzy



版主


发贴: 754
于 2004-02-24 12:07 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最近打算研究flash,代替applet之类的东西


作者 Re:获得Flash首选尺寸的方法 [Re:Jove]
rainman

阿熊

元老


发贴: 5644
于 2004-02-24 12:09 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
是按100*100显示啊

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
         codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
         WIDTH="550" HEIGHT="400" id="Untitled-1" ALIGN="">
         <PARAM NAME=movie VALUE="upload/2004/02/24/15449268.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="upload/2004/02/24/15449268.swf" quality=high bgcolor=#FFFFFF WIDTH="100" HEIGHT="100" NAME="flash" ALIGN=""
         TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
        </OBJECT>


zua edited on 2007-03-26 12:19


作者 Re:获得Flash首选尺寸的方法 [Re:rainman]
Jove



CJSDN高级会员


发贴: 1228
于 2004-02-24 12:49 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
rainman wrote:
是按100*100显示啊

<OBJECT classid="clsidBig Smile27CDB6E-AE6D-11cf-96B8-444553540000"
         codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
         WIDTH="550" HEIGHT="400" id="Untitled-1" ALIGN="">
         <PARAM NAME=movie VALUE="upload/2004/02/24/15449268.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="upload/2004/02/24/15449268.swf" quality=high bgcolor=#FFFFFF WIDTH="100" HEIGHT="100" NAME="flash" ALIGN=""
         TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
        </OBJECT>

把WIDTH="550" HEIGHT="400" 也改了吧
另外,现在bgcolor参数也是硬编码的,好像不加这个参数是保持原有背景色


Jove edited on 2004-02-24 12:53

作者 Re:获得Flash首选尺寸的方法 [Re:Jove]
rainman

阿熊

元老


发贴: 5644
于 2004-02-24 13:01 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
500,400好像不起作用哦,不过是应该改。。



作者 Re:获得Flash首选尺寸的方法 [Re:rainman]
Jove



CJSDN高级会员


发贴: 1228
于 2004-02-24 13:10 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
500*400是swf占页面的大小
而100*100是它内部图像的大小,因而会在页面中产成190000的留白
一般来说这两个值都是一致的



作者 Re:获得Flash首选尺寸的方法 [Re:Jove]
Lomone



发贴: 0
于 2004-04-29 22:02 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
有意思!!学习



reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923