如何设置 byte[] 变量的值,使其能够容纳所有 Image?

发布于 2024-12-03 22:03:42 字数 1282 浏览 2 评论 0原文

我的手机设备中有照片。我想获取照片的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻的心爱 2024-12-10 22:03:42

FileConnection 类有一个方法 fileSize() —— 调用它,并使用结果作为数组的大小。

The FileConnection class has a method fileSize() -- call it, and use the result as the size for the array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文