我在手机设备上有照片。我想获取照片的byte []值。我使用此代码来获取它:
fcDir = (FileConnection) Connector.open("file:///"+pRoot+photoDirectory+"/", Connector.READ);
if (fcDir.exists())
{
Enumeration filelist = fcDir.list("*", false);
while (filelist.hasMoreElements())
{
String fileName = (String) filelist.nextElement();
fcFile = (FileConnection) Connector.open("file:///"+pRoot+photoDirectory+"/"+fileName, Connector.READ);
dis = fcFile.openDataInputStream();
byte[] rawImg = new byte[10240];
dis.readFully(rawImg);
Image tmpImg = Image.createImage(rawImg, 0, rawImg.length);
new Fimage(tmpImg).show();
}
}
Fimage
LWUIT表单已成功显示,并且它将Image tmpImg作为其背景图像:并非所有表单都被图像占用,但只占表单的3/4。
我的问题是,我不知道为byte[] rawImg = new byte[10240];
行的参数设置的确切数字。我将参数设置为10240,但它不是很聪明。那么如何准确设置这个数字?
答案 0 :(得分:0)
FileConnection
类有一个方法fileSize()
- 调用它,并使用结果作为数组的大小。