j2me中如何下载后台图片?

发布于 2024-12-20 03:22:15 字数 139 浏览 3 评论 0原文

我有一张画布,在中心显示一张图像。该图像是通过 url 下载的。实际上还有更多图像需要下载,这意味着如果用户单击右侧,我必须显示下一张图像,如果单击左侧,我必须从背面显示另一张图像。我有存储 url 图像的字符串数组。我想在背景中下载上一张和下一张图像。怎么做呢?

I have one canvas where I am showing one image on center. This image is downloaded by url. Actually there are more images to be downloaded, that means if user clicks RIGHT I have to show next image if LEFT, I have to show another one image from backside. I have array of strings which storing images of url. I want to download previous and next image in background. How to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

离线来电— 2024-12-27 03:22:15

以下是您需要考虑的一些问题,以便此要求能够在多种设备上工作。

  1. 如果图像与设备画布大小相比较大怎么办?也就是说图像尺寸 w * h 与画布 w * h 相比非常高?
  2. 低内存设备可以加载这么大的图像吗?
  3. 跨设备的多线程模型不一致。在某些设备中,它允许您创建 10 个线程,而在其他设备中,它将停止于 2 个。
  4. 我的应用程序可以支持获取图像类型吗?那就是我正在下载 .JPG / .GIF 但我的设备不支持它。
  5. 如何缓存图像?当您导航到该图像时,您想一次又一次地加载相同的图像吗?
  6. 我是否使用 TCP/HTTP/RMI 下载图像内容?
  7. 该代码是否可以跨 JavaME 的不同风格 JVM 移植?

等等……

牢记上述一系列问题,您将为您的问题找到一个建设性的答案,那就是创建一个网络 IO 管理器和一个缓存管理器。

interface NetworkIoItem {
     Object sourceComponent;

     public void onImageDownload(Image image) {
           //Trigger the source 
     }
}

class NetworkIoManager extends Threads {
     Vector pendingRequestQueue;

     :
     :

     public void run() {
           //Wait on the pending request queue

           //Process all the elements in pending request queue
           //and again wait on this queue
     }
}

class CacheManager {
     Vector cachedContent;

     public boolean checkIfCached() {
          //Check in the cachedContent whether
          //this image exists if so return true;
     }

     public Image fetchImage() {
          //Check if the image is cached
          //if so return this cached image

          //else push a NetworkIoItem object to 
          //NetworkIOManager pending queue
     }
}

现在,对于每个图像(当前、左侧或右侧),调用 CacheManager.fetchImage(),此方法将负责为您提供缓存或从服务器下载的图像。在相同的方法中,如果图像未缓存,它将向 NetworkIoManager pendingQueue 添加 NetworkIoItem 对象并下载它。下载完成后,它将触发 NetworkIoItem.onImageDownload(...) 方法。

您可以使用 J2ME Polish 的 Touch 功能下载 中的图像NetworkIoManager

通过使用此方法,您将对请求 URL 进行异步图像获取。

Following are some of the issues that you need to consider for this requirement to work across a range of devices

  1. What if the image is big compared to the device canvas size ? That is image dimension w * h is very high compared to canvas w * h ?
  2. Can low memory devices load such big images ?
  3. Inconsistent multi-thread model across devices. That is some devices it will allow you create 10 threads while in other it will stop at 2.
  4. Can my application support the fetch image type ? That is I am downloading .JPG / .GIF but my device does not support it.
  5. How to cache the images ? Do you want to load the same image again and again when you navigate to that image ?
  6. Do I use TCP / HTTP / RMI for downloading image content ?
  7. Will this code be portable across different flavors JVM for JavaME ?

and the list continues.....

Keeping in mind the above set of issues that you will land-up with a constructive answer to your problem is to create a network IO manager and a caching manager.

interface NetworkIoItem {
     Object sourceComponent;

     public void onImageDownload(Image image) {
           //Trigger the source 
     }
}

.

class NetworkIoManager extends Threads {
     Vector pendingRequestQueue;

     :
     :

     public void run() {
           //Wait on the pending request queue

           //Process all the elements in pending request queue
           //and again wait on this queue
     }
}

.

class CacheManager {
     Vector cachedContent;

     public boolean checkIfCached() {
          //Check in the cachedContent whether
          //this image exists if so return true;
     }

     public Image fetchImage() {
          //Check if the image is cached
          //if so return this cached image

          //else push a NetworkIoItem object to 
          //NetworkIOManager pending queue
     }
}

Now for each image (current, left or right) call the CacheManager.fetchImage(), this method will take care of providing you image either cached or downloaded from server. In the same method if the image is not cached it will add NetworkIoItem objbect to the NetworkIoManager pendingQueue and download it. On completion of download it will trigger NetworkIoItem.onImageDownload(...) method.

You can use J2ME Polish's Touch feature to download a image in the NetworkIoManager

By using this approach you will do asynchronous image fetches to the request URL.

秋意浓 2024-12-27 03:22:15

做一些像..

Thread t = new Thread(new Runnable(){
  public void run() {
    // Your code to download image here as you were doing earlier,
    // for previous and next image
  }
});

t.start();

Do something like..

Thread t = new Thread(new Runnable(){
  public void run() {
    // Your code to download image here as you were doing earlier,
    // for previous and next image
  }
});

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