/**
flashattrib.java
*/
package picattrib;
import java.io.IOException;
import java.io.FileInputStream;
public class flashattrib {
public flashattrib() {
}
public static void main(String[] args) {
flashattrib flashattrib = new flashattrib();
byte[] bb=null;
image1 im = null;
try {
bb=flashattrib.readFromFile("d://aa.swf");
im = flashattrib.getAttrib(bb);
System.out.println(im.getWidth());
System.out.println(im.getHight());
bb=flashattrib.readFromFile("d://bb.swf");
im = flashattrib.getAttrib(bb);
System.out.println(im.getWidth());
System.out.println(im.getHight());
bb=flashattrib.readFromFile("d://bb.swf");
im = flashattrib.getAttrib(bb);
System.out.println(im.getWidth());
System.out.println(im.getHight());
} catch (IOException ex1) {
System.out.println(ex1);
}
System.out.println(im.getWidth());
System.out.println(im.getHight());
/*
byte aa=0;
for (int i=0;i<260;i++){
System.out.println(flashattrib.getInt(aa++));
}
*/
}
/**
* @param bb byte[]
* @param start int
* @param leng int
* @return int
*/
public int getWeizhi(int start,int weizhi,int leng,byte[] bb){
int aa=0;
if (weizhi==0) {
aa=getInt(bb[start]);
for (int i=1;i aa*=256;
int cc=getInt(bb[start+i]);
aa+=cc;
}
}else{
aa=getInt(bb[start])%16;
aa*=256;
aa+=getInt(bb[start+1]);
aa*=16;
aa+=getInt(bb[start+2])/16;
}
return aa;
}
public image1 getAttrib(byte[] bb){
image1 im=new image1();
//flash文件的宽高位置不固定,分为8种,根据第9位的值,来判断当前flash文件的具体宽高位置
//16进制50,58,60,68,70,78,80,88
switch(bb[8]){
case 80: im.setWidth(getWeizhi(9,0,2,bb)/10);
im.setHight(getWeizhi(11,1,2,bb)/10);
break;
case 88: im.setWidth(getWeizhi(9,1,2,bb)/40);
im.setHight(getWeizhi(12,0,2,bb)/10);
break;
case 96: im.setWidth(getWeizhi(9,1,2,bb)/10);
im.setHight(getWeizhi(12,1,2,bb)/10);
break;
case 104: im.setWidth(getWeizhi(10,0,2,bb)/40);
im.setHight(getWeizhi(13,0,2,bb)/10);
break;
case 112: im.setWidth(getWeizhi(10,0,2,bb)/10);
im.setHight(getWeizhi(13,1,2,bb)/10);
break;
case 120: im.setWidth(getWeizhi(10,1,2,bb)/40);
im.setHight(getWeizhi(14,0,2,bb)/10);
break;
case -128: im.setWidth(getWeizhi(10,1,2,bb)/10);
im.setHight(getWeizhi(14,1,2,bb)/10);
break;
case -120: im.setWidth(getWeizhi(10,0,3,bb)/40);
im.setHight(getWeizhi(15,0,2,bb)/10);
break;
}
return im;
}
public int getInt(byte bb){
if (bb>=0) return bb;
else return 256+bb;
}
private static byte[] readFromFile(String fileName) throws IOException
{
PicsModel model = null;
FileInputStream fin = new FileInputStream(fileName);
byte [] buf = new byte[fin.available()];
fin.read(buf);
fin.close();
return buf;
}
}
本文转自
http://blog.csdn.net/zhangjianwxh/archive/2005/06/20/398385.aspx