显示图像时是否建议使用 .ashx ?
是否建议使用处理程序来显示图像?问题是我无法右键单击并保存这些图像。它显示处理程序名称和 Asp.net 通用处理程序作为保存类型,因此我无法保存图像,但 GUI 图像的质量令人惊叹。我正在显示不同尺寸的单个图像使用 2 个处理程序并且代码工作正常,但如果我不使用处理程序,我必须单独调整它们的大小,然后将它们存储在不同的文件夹中。
Is it advisable to use a handler to display Images ? the issue is i cannot right click and save these images .It shows the Handler name and Asp.net Generic handler as save type so i cant save the image but the GUI image is amazing in quality.I am showing a single image in different sizes using 2 handlers and the code works fine but if then if I don't use the Handler i have to re size them individually and then store them in different folders.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我之前已经在网站上成功使用过这种方法,但只有在您的特定情况适合时才有用。如果您可以使用 HTML 来完成此操作,并且您的图像在服务器上的尺寸正确,那么它可能有点过大了。
如果您发现自己保存了同一图像的多个副本,那么您可能会受益于即时操作它。
在我的场景中,使用 .ashx 处理程序使我能够为每个主题上传一张大型高分辨率图像,然后将其转换为以多种不同方式使用:
然后,只需从自定义图像控件调用它并传递正确的参数即可。
编辑:
关于保存图像,只要我强制浏览器尝试将其指定为 JPEG(或其他)的 .ashx 扩展名,我就可以在我的程序中做得很好。
我无法为您提供完整的 .ashx 示例,并且您需要考虑很多子主题:
中的
Graphics
对象作为一个小示例(在 VB.NET 中),这里有一个简单的方法在给定新的宽度和高度的情况下调整图像大小:I've successfully used this method on sites before, but it's only of use if your particular case is suitable. If you can do it using HTML and your images are the correct size on the server, then it's probably overkill.
If you find yourself saving several copies of the same image then you may benefit from manipulating it on the fly.
In my scenario, using a .ashx handler enabled me to upload just one large hi-res image per subject and then transform it for use in several different ways:
Then it was just a case of calling it from a custom Image control and passing the correct parameters in.
EDIT :
Regarding saving the images, I can do it fine in mine as long as I force the .ashx extension that the browser tries to give it to be JPEG (or whatever).
I can't give you a full working .ashx example, and there are so many sub-topics you'll need to consider:
Graphics
object in .NETAs a small example (in VB.NET), here's a simple method to resize an image given the new width and height:
我不建议使用通用处理程序来显示图像。
我曾经使用这种方法,但除非图像经常变化,否则我认为这是浪费资源。
每次用户访问在
img
控件中包含图像的页面时,浏览器都必须向该文件发出 HTTP 请求,运行代码并返回流式图像。例如,如果您只是出于图像缩略图的目的这样做,那么我建议每当在整个应用程序中上传图像时都保存缩略图的物理版本。
这样做的另一个优点是图像不会像代码那样出错!
I wouldn't recommend using generic handlers for displaying images.
I used to use this approach, but unless the image is changing quite often, I think it is a waste of resources.
Every time a user goes to a page which contains your image in an
img
control, the browser is having to make a HTTP Request to that file, run the code, and return a streamed image.If you are only doing this for image thumbnail purposes, for example, I would recommend saving physical versions of the thumbnail image whenever the image is uploaded throughout the app.
Another advantage of this, is that images don't error as much as code!