节省宽带可以帮助我吗? [英] Save broadband can u help me with this ?

查看:59
本文介绍了节省宽带可以帮助我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公开  Form1 
Dim numbrofpicturebox 作为 整数 = 1
昏暗位置作为 整数 = 1
私有 Form1_Load(发件人作为 对象,e 作为 EventArgs)句柄 MyBase .Load
执行直到numbrofpicturebox = 5
Dim picturebox1 < span class =code-keyword> As PictureBox

picturebox1.Location = 点(位置, 10
picturebox1.SizeMode = PictureBoxSizeMode.Zoom
picturebox1.BorderStyle = BorderStyle.FixedSingle
picturebox1.Height = 110
picturebox1.Width = 125
.Controls .Add(picturebox1)
numbrofpicturebox = numbrofpicturebox + 1
location = location + 135
循环
结束 Sub
结束





我尝试过:



如果我将图像添加到图片框中,它每次都会下载图像,因为我已经加载了大约500个图像。

所以运行应用程序加载需要一个小时? br />
有更好的方法吗?

解决方案

加载更好的方法!

具体做什么取决于哪里图像来自,它们改变的频率,为什么你想要一次显示500张图像!在我们建议您做什么之前,您需要对此进行合理的思考。



您使用下载意味着您可以通过网络获取它们网站,并在某些时候将它们加载到那些图片框中 - 但是你没有显示代码,因此在提出建议时很难准确。

但是......首先,看看图像变化的频率和图像的类型。如果它们在大部分时间都是相同的,那么在本地缓存它们而不是每次都下载它们。下载图像并不是那么快,特别是如果它们是大图像(并且你放大它们,所以我怀疑它们是)。作为JPG文件,500 x 1200 x 1000的图像可能是60MB,但如果它们是BMP文件则大约是2.4GB!即使在快速连接上,这种数据提供也会占用大量带宽。即使是60MB也可能需要很长时间才能使源处于繁忙状态或缓慢。在本地缓存它们意味着瓶颈消失了 - 但仅适用于每次运行应用程序时变化不大或不是新设置的图像。如果你可以把它们当作JPG或PNG而不是BMP那么可以产生巨大的差异!



然后看看你为什么要把这么多的图像加载到一个页面中:你在你展示的代码中创建了5个图片框,但是如果你创建了500,那么这只会有点愚蠢并且会导致各种各样的减速(即使图像是jpg,你的app也可能使用2.4 GB的内存,可能更多一旦你将它们加载到Image类实例中以显示它们。取决于你的系统和它的可用内存......这可能真的会破坏较小的系统!)

它也值得加载每个图像,(如果必要的)并创建自己的缩略图,而不是让系统调整它们的大小:然后你可以处理完整的图像并显示缩略图,缩略图将更小更快地使用(将它与缓存结合起来!) />
你需要一次加载所有500吗?你不能一次在屏幕上获得那么多,所以为什么加载用户看不到的?对它们进行分页,只在需要时加载它们。

根本不要使用PictureBox。使用一个面板为他们所有,并在它的Pait事件中自己绘制。这可以节省时间 - 不是你想要的时间,但是一旦你遇到了主要的瓶颈就会充足 - 因为你没有创建控件,每个控件都需要一个句柄,一个消息循环,以及...... PictureBox很好,但是数量不大! :笑:

Public Class Form1
    Dim numbrofpicturebox As Integer = 1
    Dim location As Integer = 1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Do Until numbrofpicturebox = 5
            Dim picturebox1 As New PictureBox
  
            picturebox1.Location = New Point(location, 10)
            picturebox1.SizeMode = PictureBoxSizeMode.Zoom
            picturebox1.BorderStyle = BorderStyle.FixedSingle
            picturebox1.Height = 110
            picturebox1.Width = 125
            Me.Controls.Add(picturebox1)
            numbrofpicturebox = numbrofpicturebox + 1
            location = location + 135
        Loop
    End Sub
End Class



What I have tried:

how if i add image to picture box it download the image every time for i have loaded around and more then 500 image in a list.
so to run the application load takes an hour ?
is there a better way ?

解决方案

Load of better ways!
Exactly what to do depends on where the images come from, how often they change, why you want to display 500 images at once anyway! And you need to do a reasonable amount of thinking about this before we can advise you what to do.

Your use of "download" implies you get them from a web site, and are loading them into those picture boxes at some point - but you don't show the code for that so it's difficult to be accurate when making suggestions.
But... first off, look at how often the images change and what type of images they are. If they are the same set most of teh time, then cache them locally instead of downloading them each time. Downloading images isn't that quick, particularly if they are large images (and you zoom them so I suspect they are). 500 images that are 1200 x 1000 will be maybe 60MB as JPG files, but around 2.4GB if they are BMP files! That give of data takes serious amounts of bandwidth, even on a fast connection. Even 60MB may take significant time is the source is busy, or slow. Caching them locally means that "bottleneck" is gone - but only for images that don't change much, or aren't a new set each time you run your app. If you can get them as JPG or PNG instead of BMP that can make a huge difference!

Then look at why you are loading so many images into a page anyway: you create 5 picture boxes in the code you show, but if you are creating 500 then that's just a bit silly and will cause all sorts of slowdowns (your app may be using that 2.4 GB of memory even if the images are jpg, possibly more once you load them into Image class instances to display them. Depending on your system and it's available memory...that could really hammer smaller systems!)
It's also worth loading each image, (saving it if necessary) and creating your own thumbnail instead of getting the system to resize them: you can then dispose the "full" image and display the thumbnail, which will be smaller and quicker to work with (combine this with caching as well!)
Do you need to load all 500 at once? You can't get that many on the screen at once, so why load ones the user can't see? Page them and only load them when you need them.
Don't use a PictureBox at all. Use one Panel for them all, and draw them yourself in it's Pait event. This can save time - not the hour you want, but plenty once you've got the major bottlenecks out of the way - because you aren't creating controls, each of which need a handle, and a message loop, and ... PictureBox is good, but it's not good in large numbers! :laugh:


这篇关于节省宽带可以帮助我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆