如何使用 javascript 使用 asp.net 图像缩放器
我使用 javascript/jquery 来填充 html 网页。在 IE 中工作正常,但在 Firefox 或 Chrome 中,当我仅单击链接时,只要显示图像,图像就不会显示:
http://localhost:12240/ImageResize.aspx?imgsrc=images/test.jpg&width=100
使用 JavaScript我创建这个 html 代码:
<div class="item related-padding">
<div class="item-container item-0">
<div class="item-content" style="background:url(ImageResize.aspx?imgsrc=images/test.jpg&width=127) no-repeat;"></div>
<div class="item-type video"></div>
</div>
<div class="item-caption">Test</div>
</div>
我相信问题出在 C# 中,ASP.NET 标头
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Random random = new Random();
int randomNumber = random.Next(1000000);
//Response.AddHeader("content-disposition", "attachment;filename=" + $randomNumber.ToString() + ".jpg");
/*resize happens here*/
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.Flush();
Response.End();
bmp.Dispose();
image.Dispose();
有什么想法吗?
我想要的只是调整图像大小并将其输出为 jpg
I use javascript/jquery to fill with html a web page. In IE works fine but in Firefox or Chrome the image is not shown wherever the image is shown when i click only the link:
http://localhost:12240/ImageResize.aspx?imgsrc=images/test.jpg&width=100
With javascript i create this html code:
<div class="item related-padding">
<div class="item-container item-0">
<div class="item-content" style="background:url(ImageResize.aspx?imgsrc=images/test.jpg&width=127) no-repeat;"></div>
<div class="item-type video"></div>
</div>
<div class="item-caption">Test</div>
</div>
I believe the problem is in C#, ASP.NET headers
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/jpg";
Random random = new Random();
int randomNumber = random.Next(1000000);
//Response.AddHeader("content-disposition", "attachment;filename=" + $randomNumber.ToString() + ".jpg");
/*resize happens here*/
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.Flush();
Response.End();
bmp.Dispose();
image.Dispose();
any ideas?
All i want is to resize the image and output it as jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加 而不是带有背景图像的 div。
Add the <img src="ImageResize.aspx?imgsrc=images/test.jpg&width=127" alt=""/> instead of div with background image.
您的问题错过了中肯答案所需的详细信息,但您可以查看以下一些提示:
CSS 中的相对 URI 并不总是以相同的方式处理,请检查 FireBug 或 HTTP 嗅探器是否正在检索正确的相对 URI。 IE 和其他浏览器之间曾经存在差异,不确定是否仍然相同。
错误很可能出现在您的 JavaScript 中,但您没有显示出来。您可以使用 javascript 控制台进行检查和/或通过在警报框或文本框中打印结果并手动渲染结果来检查,看看会发生什么(仔细查看正确的转义)。
您不使用&符号的实体,尽管我很难想象浏览器会关心它
Response.Clear()
,如果您通过普通页面请求创建响应,则可能会创建一个残缺的响应流,其中包含来自该页面的标头和数据你不想要使用文件中的常规图像测试您的代码,看看 CSS 是否仍然有效(当然还有 JavaScript)。分别测试 JavaScript 输出和 CSS,以确保找到正确的罪魁祸首(CSS、JS、服务器端 C# 或其他)。
Your question misses the details needed for a to-the-point answer, but here are some hints you can look at:
Relative URIs in CSS are not always treated the same way, check with FireBug or an HTTP sniffer whether the correct relative URI is being retrieved. There used to be a difference here between IE and others, not sure it's still the same.
It's very likely that the error is in your JavaScript, which you don't show. You can check that with the javascript console and/or by printing out the result in an alert box or textbox and rendering that by hand, see what happens (look carefully at correct escaping).
You don't use an entity for the ampersand, though I can hardly imagine a browser would care about that
You don't do a
Response.Clear()
, which, if you create the response through a normal page request, can create a crippled response stream with headers and data from the page that you don't want there.Test your code with a regular image on file, see if the CSS still holds (and the JavaScript, of course). Test JavaScript output and CSS separately to make sure to find the right guilty party (CSS, JS, server side C# or else).