读取手机相册里的照片

liangruifang 2009-12-18 10:24:46
急求读取手机相册里的照片程序(j2me)
...全文
193 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hy19880714 2009-12-24
  • 打赏
  • 举报
回复
UP
wholesale3151 2009-12-23
  • 打赏
  • 举报
回复
byte[] b = new byte[1024];
int len = 0;
ByteArrayOutputchinese wholesalers baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
while((len = is.read(b)) != -1){
dos.write(b, 0, len);
cccloveyf 2009-12-23
  • 打赏
  • 举报
回复
up
LLL710451618 2009-12-22
  • 打赏
  • 举报
回复
ding
vclongking 2009-12-21
  • 打赏
  • 举报
回复
学习
ahhh90h 2009-12-20
  • 打赏
  • 举报
回复
..........
blueduan1985 2009-12-18
  • 打赏
  • 举报
回复

private Image loadImage(String address) {
FileConnection fc;
DataInputStream is;
Image img = null;
try {
fc = (FileConnection) Connector.open(address,Connector.READ);
if (fc.exists()) {
is = fc.openDataInputStream();
byte[] tmp = readBytes(is, (int) fc.fileSize());
img = Image.createImage(tmp, 0, tmp.length);
is.close();
}
fc.close();
} catch (Exception e) {
}
return img;
}


其中address为文件地址,具体写法参照2楼
pjw100 2009-12-18
  • 打赏
  • 举报
回复
读取相册里面的图片首先要用到FileConnection
我刚用N95试了下,拍摄的相片存储在C:/Data/Images/200912/200912A0下,红色的部分可能不一样,一般存储在C:/Data/Images/下,你需要递归这个目录。
遍历目录的方法:
http://blog.csdn.net/pjw100/archive/2009/12/18/5028662.aspx

读取图片的方法:

/**
* 读取图片
* @param path
* @return
*/
public byte[] readImage(String path){
FileConnection fc = null;
try{
fc = (FileConnection)Connector.open(path,Connector.READ);
InputStream is = fc.openInputStream();

byte[] b = new byte[1024];
int len = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
while((len = is.read(b)) != -1){
dos.write(b, 0, len);
}
byte[] data = baos.toByteArray();
return data;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}

比如C:/Data/Images/ 文件夹下有一张me.jpg,调用的时候的path = "file:///c:/data/images/me.jpg";
kf156 2009-12-18
  • 打赏
  • 举报
回复
源码没有
建议去看JSR75 FileConnection
liangruifang 2009-12-18
  • 打赏
  • 举报
回复
谢谢!!!
kongyanmin 2009-12-18
  • 打赏
  • 举报
回复
public void read(String url){
FileConnection fc = null;
InputStream in = null;
try{
fc = (FileConnection) Connector.open(url);
in = fc.openInputStream();
try{
ByteArrayOutputStream output = new ByteArrayOutputStream();
int ch;
while((ch = in.read()) != -1){
output.write(ch);
}
byte[] bytebuffer = output.toByteArray();
Image image = Image.createImage(bytebuffer, 0, bytebuffer.length);
form.append(image);
output.close();
}catch(IOException e){
e.printStackTrace();
}
}catch(IOException e){
e.printStackTrace();
}finally {
if(in != null){
try{
in.close();
}catch(IOException e){
e.printStackTrace();
}
}
if(fc != null){
try{
fc.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧