1)从本地磁盘读取图片
FileConnection fc = (FileConnection) Connector.open("file:///map/zhuangshi07.png");//path是图片路径
InputStream is = fc.openInputStream();
byte bufferImage[] = new byte[(int) fc.fileSize()];
bufferImage = InputStreamToByte(is);
is.close();
fc.close();
2) 将输入流转换为字节数组
private byte[] InputStreamToByte(InputStream is) throws IOException {
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = is.read()) != -1) {
bytestream.write(ch);
}
byte imgdata[] = bytestream.toByteArray();
bytestream.close();
return imgdata;
}
3)使用字节数组创建Image对象
img = Image.createImage(bufferImage, 0, bufferImage.length);