首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> 移动短信技术 -> EMS图片格式转换(Java)程序  
EMS图片格式转换(Java)程序


文章类别:移动短信技术 来源: 作者: 发表日期:2005-10-4 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

本人刚接触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结构!  的帖子,不正确的地方,请指教!

上一篇:图片格式整理(增加alcatel) 下一篇:MIDI文件结构分析及生成方法
本栏目热门文章
·手机短信息SMS的程序开发 2005-10-4
·SMS开发的资料包 2005-10-4
·基于CMPP3.0的企业短信网关API设计 2005-10-4
·编写SMS程序入门 2005-10-4
·基于短信网关WAP推送的实现 2005-10-4
·对于开发SMS初学者的,经常用到的几个函数。 2005-10-4
·各网关厂商API接口 2005-10-4
·基于CMPP2及东软API短信平台的开 2005-10-4
·SmartPhone手机上查看QQ天气预报 2005-10-4
·移动业务代码规范方案 2005-10-4
新近更新文章
·免费实用!3步搞定电邮手机推送! 2006-3-8
·MIDP游戏开发中处理文字的换行方案 2005-10-12
·MIDP2.0手机上手电筒程序的实现 2005-10-6
·基于短信网关WAP推送的实现 2005-10-4
·基于CMPP3.0的企业短信网关API设计 2005-10-4
·SmartPhone手机上查看QQ天气预报 2005-10-4
·Windows CE下驱动程序开发基础 2005-10-4
·基于CMPP2及东软API短信平台的开 2005-10-4
·用J2ME的通用联网框架开发联网的应用程序 2005-10-4
·利用J2ME在移动设备上实现动画的解决方案 2005-10-4
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: