如何设置 byte[] 变量的值,使其能够容纳所有 Image?
我的手机设备中有照片。我想获取照片的 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 表单已成功显示,并且它以图像 tmpImg 作为其背景图像:并非所有表单都被图像占据,但只有表单的 3/4 。
我的问题是,我不知道为 byte[] rawImg = new byte[10240];
行的参数准确设置什么数字。我将参数设置为 10240 ,但这不是很聪明。那么如何准确设置这个数字呢?
I have photos in the phone device. I want to get the byte[] value of a photo. I use this code to get it :
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();
}
}
The Fimage
LWUIT Form is shown successfully and it has the Image tmpImg as its background image : not all the Form is occupyied by the Image but only 3/4 of the Form.
My problem is that I do not know what number to set exactly for the argument at the line byte[] rawImg = new byte[10240];
. I set the argument to 10240 , but it is not very clever. So how to set exactly this number ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FileConnection
类有一个方法fileSize()
—— 调用它,并使用结果作为数组的大小。The
FileConnection
class has a methodfileSize()
-- call it, and use the result as the size for the array.