简体   繁体   English

黑莓手机中的图像浏览器

[英]Image Browser in blackberry

I want to make an image browser for my application where the user can select the image that he wants from the phone. 我想为我的应用程序制作一个图像浏览器,用户可以在其中从电话中选择想要的图像。 I am reading each image from the phone like this: 我正在从手机中读取每个图像,如下所示:

FileConnection fileConnection = (FileConnection)Connector.open((String) imm.elementAt(i));
InputStream inputStream = fileConnection.openInputStream();
byte[] imageBytes = new byte[(int)fileConnection.fileSize()];
inputStream.read(imageBytes);
inputStream.close();
fileConnection.close();

EncodedImage image = EncodedImage.createEncodedImage(imageBytes, 0, -1);
EncodedImage image1 = scaleImageEncoded.scaleImage(image, (int) (Display.getWidth() / 4) - 10, (int) (Display.getWidth() / 4) - 10);
BrowseBitmapField field = (BrowseBitmapField) manager.getField(i);
field.setBitmap(image1.getBitmap());
field.setEncodedImage(image);

When the phone included many images, this process bicomes too slow and the phone needs a lot of time to get them. 当手机包含许多图像时,此过程会变得很慢,并且手机需要大量时间才能获取它们。 Is there any faster way to read an image from the memory of the phone and display it? 有没有更快的方法可以从手机的内存中读取图像并进行显示?

Thanks in advance 提前致谢

In addition to what jprofitt recommends I'd suggest to do the following: 除了jprofitt建议之外,我还建议您执行以下操作:

  1. When you create a resized version of an image you can save it for future usages. 创建图像的调整大小版本后,可以将其保存以备将来使用。 Next time user clicks on the same image you first check for a resized image presence and if not present only then read/resize the original image. 下次用户单击同一图像时,您首先检查是否存在调整大小的图像,如果不存在,则仅读取/调整原始图像的大小。 So you can save time spent on future resizing + don't forget that resized image file size is in times smaller than original, so future reading will happen in times faster. 因此,您可以节省花在将来调整大小上的时间+不要忘了调整大小后的图像文件大小会比原始大小小几倍,因此将来的读取速度会更快。

  2. Do not try to read/resize all images in the dir at once. 不要尝试一次读取/调整目录中所有图像的大小。 Do this only for those that should be visible for the user at the moment. 仅对当前对用户可见的对象执行此操作。 For instance, if the the dir has 100 images you'll most likely need A LOT of time to read/resize/attach to manager all images. 例如,如果目录中有100张图像,则您很可能需要大量时间来读取/调整大小/附加以管理所有图像。 However user sees just 6 or 8 images on the screen at a time. 但是,用户一次只能在屏幕上看到6或8张图像。 If user scrolls up/down, then it's right time to request reading/resizing/etc for those images that now should be visible, but have not been read/resized yet. 如果用户向上/向下滚动,则是时候请求读取/调整大小/等这些现在应该可见但还没有被读取/调整大小的图像。

  3. Reading/resizing should be done on a background Thread in order not to block the main UI-thread. 读取/调整大小应在后台Thread上完成,以免阻塞主UI线程。 In other words user should be able to scroll the screen while reading/resizing happens on a background Thread . 换句话说,在后台Thread上进行读取/调整大小时,用户应该能够滚动屏幕。 I recommend to arrange a queue of reading/resizing tasks and execute them on a background worker Thread . 我建议安排读取/调整大小任务的队列,并在后台工作Thread上执行它们。 When a task is done on worker Thread and it's time to update UI of the screen with resized image, then use UiApplication.invokeLater(Runnable action) for that. 当在工作Thread上完成任务时,是时候使用调整大小的图像更新屏幕的UI了,然后使用UiApplication.invokeLater(Runnable action)

You may try using a BufferedInputStream. 您可以尝试使用BufferedInputStream。 I've had luck with it speeding up my read times, might work for you as well. 我很幸运,它可以加快我的阅读时间,也可能对你有用。

 BufferedInputStream inputStream = new BufferedInputStream(fileConnection.openInputStream());
 byte[] imageBytes = new byte[(int)fileConnection.fileSize()];
 inputStream.read(imageBytes, 0, imageBytes.length);

The guy who posted at the below URL figured out you can get the thumbnail from BBThumbs.dat and posted some code. 在以下URL上发布的人发现您可以从BBThumbs.dat获得缩略图并发布一些代码。 I haven't tried it myself but if it works the time savings should be very significant. 我自己还没有尝试过,但是如果成功的话,节省的时间将非常可观。

http://supportforums.blackberry.com/t5/Java-Development/Thumbnails-work-around/td-p/343870 http://supportforums.blackberry.com/t5/Java-Development/Thumbnails-work-around/td-p/343870

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM