网络软件 系统工具 应用软件 图形图像 多媒体类 免费游戏 安全相关 免费音乐 网页素材 电子书籍 考试考题 建站源码
教育教学 多媒体类 编程开发 操作系统 游戏天地 娱乐天地 简历求职 站长专区 网页设计 安全技术 图形图像 文学驿站
业界资讯 | 图形图像 | 操作系统 | 网络冲浪 | 工具软件 | 办公软件 | 媒体动画 | 精文荟萃 | 认证考试 | 网页设计 | 技术开发 | 专栏
当前位置:热点网络学院技术开发ScriptVbScriptEMS图片格式转换(Java)程序
精品推荐
热点TOP10
·Microsoft VBscript运行时错误'800a000d'的解决方案
·验证email地址是否合法完整实例
·判断一个字符串里面包含有中文或者英文
·使用VBScript操作Html复选框(CheckBox)控件
·让文本输入框只能输入数字
·vbscript与javascript传递变量
·URL编码处理
·获取汉字拼音的第一个字母
·EMS图片格式转换(Java)程序
·vbscript错误代码及对应解释大全
·编写高质量的VB代码
·检测IP地址是否真正合法的函数
·JavaScript幻灯片效果
·js入门·循环与判断/利用函数的简单实例/使用对象/列举对象属性的名称
·身份验证常用正则表达式
·如何使用FSO搜索硬盘文件
·为Nokia S60编写移动游戏之二
·在VB中利用Word宏命令开发ASP组件
·VBScript教程 第二课 在HTML页面中添加VBscript代码
·VBScript教程 第一课 什么是 VBScript
EMS图片格式转换(Java)程序
日期:2005年4月25日 作者:热点网络学院 查看:[大字体 中字体 小字体]
本人刚接触EMS,还有很多地方不明
这个程序对16*16,32*32,72*14有效,可直接得到要发送的byte[140],40*35还没测试,本着公开源码的精神,献丑了

//victorachc@163.com
import java.io.*;

public class preResult{
//pos is the pixel data start postion
private int pos;
//bitmap's width and height
private byte w;
private byte h;
//bmp is byte[] of the bmp file
private byte[] bmp;
//result is the byte[] which save the result
private byte[] result = new byte[140];
//result[] length
private int rlen;

protected  preResult(String fn) throws IOException {
FileInputStream fin = new FileInputStream(fn);
//read bmpdata to byte array bmp
int bmplen = fin.available();
bmp = new byte[bmplen];
fin.read(bmp);
w=bmp[18];
h=bmp[22];
fin.close();
}

//check if it is 1 bit/pixel
public void isValid() throws Exception {
if(bmp[28]==1) return;
else  throw new Exception("pixel is not 1");
}

//check if the bmp length is valid
public boolean checkDataLen() throws Exception {
int len=(bmp[2]-bmp[10])>=0?(bmp[2]-bmp[10]):(bmp[2]-bmp[10]+256);
if (len==(w*h/8)){
return true;
}
else if(len*3/4==w*h/8){
System.out.println("This is variable bmp!");
return true;
}
else throw new Exception("length is invalid");
}

public void getHead() throws Exception {
if(w==16&&h==16){
result[0]=35;
result[1]=17;
result[2]=33;
result[3]=0;
pos=4;
rlen=36;
return;
}
else if(w==32&&h==32){
result[0]=-125;
result[1]=16;
result[2]=-127;
result[3]=0;
pos=4;
rlen=132;
return;
}
else if(((w%8)==0)&&((w*h)<=1024)){
int p=w*h/8+5;
result[0]=(byte)((p<=127)?p:(p-256));
result[1]=18;
result[2]=(byte)(result[0]-2);
result[3]=0;
result[4]=(byte)(w/8);
result[5]=h;
pos=6;
rlen=p+1;
return;
}
throw new Exception("header error");
}

public void getBody(){
//according to the EMS specification,w is w/8
int wid=w/8;
if(pos==4){
//lh is loop height,lw is loop width
for(int lh=0;lh<h;lh++){
for(int i=bmp.length-(lh+1)*wid;i<bmp.length-lh*wid;i++){
result[pos] = bmp[i];
pos++;
}
}
}
else if(pos==6){
wid = wid+3;
for(int lh=0;lh<h;lh++){
for(int i=bmp.length-(lh+1)*wid;i<bmp.length-lh*wid;i++){
if(i<bmp.length-lh*wid-3){
result[pos] = bmp[i];
pos++;
}
}
}
}
//result has been build,you can check the byte[] here
}

public void putResultIntoFile() throws IOException{
FileOutputStream fout = new FileOutputStream("test.tmp");
fout.write(result);
fout.close();
}

public static void main(String[] args) throws IOException,Exception {
preResult pR = new preResult("d:\\Tom.bmp");
pR.isValid();
try{
pR.checkDataLen();
}
catch(Exception e){e.printStackTrace();}
pR.getHead();
pR.getBody();
pR.putResultIntoFile();
}
}

这段程序参考了斑竹:BMP结构!  的帖子,不正确的地方,请指教!

(出处:http://www.vipcn.com

关于我们 | 帮助(?) | 版权声明 | 友情连接 
Copyright 2005-2005 viphot.com All Rights Reserved.
Powered by:mesky