将图像 URL 添加到列表字段中的位图图像

发布于 2024-09-16 05:28:58 字数 360 浏览 2 评论 0原文

我有 50/100 个带有特定文本的图像 url,我将它们添加到向量中,添加带有回调的列表字段,

我每次都使用函数调用 UrlToImage 下载图像 我遇到问题,列表太慢,下载图标显示在模拟器的右上角。

UrlToImage img = new UrlToImage(imageUrl);
bit = img.getbitmap();
pic = new BitmapField(bit); 
g.drawBitmap(xpos, y+10, bit.getWidth(), bit.getHeight(), bit, DrawStyle.LEFT,0);

无法在整个列表中平滑滚动。

有什么想法,评论。

I have 50/100 image url with specific text, i add them in vector, add listfield with callback,

I am downloading the image every time with a function call UrlToImage I am facing problem, the list is too slow , download icon showing on the top right side of simulator.

UrlToImage img = new UrlToImage(imageUrl);
bit = img.getbitmap();
pic = new BitmapField(bit); 
g.drawBitmap(xpos, y+10, bit.getWidth(), bit.getHeight(), bit, DrawStyle.LEFT,0);

Can't scroll smoothly throughout the list.

Any idea, comments.

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

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

发布评论

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

评论(2

月朦胧 2024-09-23 05:28:58

你的格式全乱了,但如果我理解正确的话,你每次回调都会下载?

避免这种情况的一种方法是创建一个线程,在需要屏幕时启动,并异步执行下载(每次一次!)并将图像粘贴到缓存中。然后,drawListRow 回调只是从缓存中提取。

Your formatting is all messed up, but if I understand you correctly, you're downloading upon every callback?

One way to avoid that is create a thread that kicks off when the screen is needed, and asynchronously do the downloads (once each!) and stick the images in a cache. Then the drawListRow callback just pulls from the cache.

清浅ˋ旧时光 2024-09-23 05:28:58

看起来好像您的代码正在 Paint 方法内执行。这一切都发生在 UI 线程上(这意味着每次绘制时,您都会阻塞 UI、发出请求、等待响应、设置图像,然后绘制图像)。由于请求可能需要大约 3 秒,因此您的 UI 将冻结那么长时间。

您应该做的是在类的构造函数中获取图像,设置类的实例变量,然后使用该实例变量使用 g.drawBitmap 。

简而言之,paint 方法中的唯一代码应该是 g.drawBitmap,以防止滚动不稳定。

It appears as though your code is executing inside the paint method. This all occurs on the UI thread (meaning that you block the UI, make a request, wait for a response, set the image, and then draw the image, every time a paint occurs). Seeing as a request can take about 3 seconds, your UI will freeze for that long.

What you should be doing it fetching your image in the constructor of your class, set an instance variable of your class, and then g.drawBitmap with that instance variable.

In short, the only code in your paint method should be the g.drawBitmap, in order to prevent the choppy scrolling.

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