首页 \ 问答 \ Image.FromFile非常慢。(Image.FromFile is very SLOW. Any alternatives, optimizations?)

Image.FromFile非常慢。(Image.FromFile is very SLOW. Any alternatives, optimizations?)

我有一个winforms图像列表,其中包含像200图像256x256。

我使用Images.FromFile方法加载图像,然后将它们添加到图像列表中。

根据ANTS .NET分析器,该程序的一半时间用于Images.FromFile 。 有没有更好的方法来加载图像添加到图像列表?

可能优化的另一件事是,加载的图像大于256x256。 那么有没有办法通过调整它们的大小来加载它们? 如果它们的高度大于256像素,我只想统一缩放它们。

任何想法来优化这个?

编辑:他们是JPEG。


I have a winforms image list which contains say like 200 images 256x256.

I use the method Images.FromFile to load the images and then add them to the image list.

According to ANTS .NET profiler, half of the program's time is spent in Images.FromFile. Is there a better way to load an image to add to an image list?

Another thing that might be optimized is, the images that are loaded are larger than 256x256. So is there a way to load them by resizing them first or something? I just want to uniform scale them if they their height is larger than 256 pixels.

Any idea to optimize this?

EDIT: They are JPEGs.


原文:https://stackoverflow.com/questions/1053509
更新时间:2023-09-11 11:09

最满意答案

理论上,编码客户端不会比编码服务器端更危险。 确保其安全的关键在于如何在呈现数据的所有位置放置合适的编码。 您当然可以在客户端和服务器端安全地创建用于提交用户提交数据的良好实现。 实际上,实现输出编码客户端的一个缺点是潜在的攻击者可以轻松检查您的源代码是否存在缺陷。 这意味着如果客户端编码实现中存在缺陷,那么比服务器端更容易找到(假设是封闭的源系统)。 如果你正在开发开源软件,那么这一点是没有意义的。

同样如你所说,修改你的客户端编码代码的攻击者是一个没有问题的人,因为他们只会修改他们自己的代码副本而不会影响其他访问者。

海事组织,让客户端处理编码实际上更清洁,特别是如果您正在开发一个由Web和本地移动应用程序共享的API。 您不希望移动应用程序必须将HTML编码值转换回原始格式。


In theory, encoding client-side is no more dangerous than encoding server-side. The key to making it secure really is in how rigourous you are in putting suitable encoding in all the places which renders your data. You can certainly create a good implementation for rendering user submitted data safely on client and server sides. Practically though, a drawback of implementing output encoding client side is that a potential attacker can easily examine your source code for flaws. This means that if there are bugs in your client-side encoding implementation, it will be easier to find than say on the server-side (assuming a closed source system). If you are developing open source software, then this point is moot.

Also as you said, an attacker modifying your client-side encoding code is a non-issue as they will only be modifying their own copy of the code and will not affect other visitors.

IMO it is actually cleaner to let the client handle encoding especially if you are developing an API which is shared by web and native mobile applications. You don't want your mobile application to have to convert HTML encoded values back to it's original form.

相关问答

更多
  • 这是一个很多问题。 为什么客户端编码被认为不安全? 只要正确和一致地完成,客户端编码就没问题。 由于客户端编码不需要担心UTF-7攻击等字符编码级别的攻击,因此客户端编码的编码通常较低。 每当我尝试使用jQuery.val(untrusted_data)或element.value = untrusted_data设置值时,它似乎足够安全。 那么它真的是XSS安全还是我错过了这里的任何案例? 假设untrusted_data是一个字符串,并且其值被设置的元素是流或块元素中的常规文本节点,那么你很好。 如果正 ...
  • 为什么会这样? 您将生成以下内容: Foo Foo 这些都不是有效的html / javascript。 第一个在引号中有不匹配,因此标签被破坏。 第二个没有javascript。 它有一个title属性,包含字符< , s , c等...这不是javascript。 这只是一些看起来像javascript的TEXT。 要做X ...
  • 那么,你应该总是担心:)但是,是的,小胡子完成了你在这里谈论的目标,保护你的示例免受XSS(除非你直接输出值到 There are plenty of ways of doing it, this i ...
  • 一目了然,将QString参数转换为Utf8 QByteArray然后返回QString似乎很奇怪: QString text = response.toUtf8(); 当toUtf8()返回的QByteArray被赋值给text ,我认为假设QByteArray包含一个Ascii (char*)缓冲区。 At a glance, the line where you convert the QString parameter to a Utf8 QByteArray and then back to a ...
  • 理论上,编码客户端不会比编码服务器端更危险。 确保其安全的关键在于如何在呈现数据的所有位置放置合适的编码。 您当然可以在客户端和服务器端安全地创建用于提交用户提交数据的良好实现。 实际上,实现输出编码客户端的一个缺点是潜在的攻击者可以轻松检查您的源代码是否存在缺陷。 这意味着如果客户端编码实现中存在缺陷,那么比服务器端更容易找到(假设是封闭的源系统)。 如果你正在开发开源软件,那么这一点是没有意义的。 同样如你所说,修改你的客户端编码代码的攻击者是一个没有问题的人,因为他们只会修改他们自己的代码副本而不会影 ...
  • 常见的XSS攻击向量是攻击者以某种方式将JS代码输入到Web应用程序中的情况,这样该代码就会显示在网页的DOM中并因此被激活。 为了防止这种XSS,您必须确保后端服务器不向浏览器发送用户生成的(未清理的)html ...(这与qooxdoo无关)。 也就是说,常规qooxdoo小部件通常不会将数据显示为html,因此即使没有聪明的服务器,您也是相当安全的。 qx.ui.basic.Label小部件及其后代是个例外。 如果设置rich属性,Label小部件可以直接显示HTML。 默认情况下, rich属性设置 ...
  • 并不难,假设你可以弄清楚究竟是什么触发了ASP.Net XSS过滤器。 例如,这将修复您显示的案例: