13,100
社区成员
发帖
与我相关
我的任务
分享
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;
}
/**
* 读取图片
* @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;
}