1
私がやっているのは、現在のブラウザの幅と高さに基づいてイメージのサイズとサイズを変更してイメージソースを更新することです。すべてがローカルで素晴らしい作品ですが、私の地元の環境の外で画像は更新されません。Response.OutputStreamを使用したJquery img srcの更新
どのようなヘルプやヒントをいただければ幸いですか?
画像
<img class='image' src='./ImageResize.aspx?image=http://img.dailymail.co.uk/i/pix/2008/04_02/alligatorL_468x343.jpg' />
jQueryのSRC操作
//Adds resize image demensions
$('image').each(function() {
var sSource = $(this).attr('src');
sSource = sSource + "&width=" + $(window).width + "&height=" +
$(window).height();
$(this).attr('src', sSource);
});
Asp.netコード
protected void ImageWork()
{
var sPath = "";
var sWidth = 0;
var sHeight = 0;
if (Request["image"] != null)
{
sPath = Request["image"].ToString();
}
if (Request["width"] != null & Request["height"] != null)
{
sWidth = Convert.ToInt32(Request["width"]);
sHeight = Convert.ToInt32(Request["height"]);
}
if (!string.IsNullOrEmpty(sPath) & (sWidth > 0) & (sHeight > 0))
{
if (sPath.Contains("http"))
{
MemoryStream xPath;
WebClient wc = new WebClient();
byte[] originalData = wc.DownloadData(sPath);
xPath = new MemoryStream(originalData);
using (Bitmap image = new Bitmap(xPath))
{
int xWidth = image.Width;
int xHeight = image.Height;
if ((xWidth < sWidth) & (xHeight < sHeight))
{
Response.ContentType = "image/Jpeg";
image.Save(Response.OutputStream, ImageFormat.Jpeg);
}
else
{
xWidth = (int)Math.Floor(((double)image.Width * ((double)sWidth/(double)image.Width)));
xHeight = (int)Math.Floor((double)image.Height * ((double)sHeight/(double)image.Height));
using (Bitmap newImage = new Bitmap(image, xWidth, xHeight))
{
Response.ContentType = "image/Jpeg";
newImage.Save(Response.OutputStream, ImageFormat.Jpeg);
}
}
}
}
else
{
var xPath = sPath;
using (Bitmap image = new Bitmap(xPath))
{
int xWidth = image.Width;
int xHeight = image.Height;
if ((xWidth < sWidth) & (xHeight < sHeight))
{
Response.ContentType = "image/Jpeg";
image.Save(Response.OutputStream, ImageFormat.Jpeg);
}
else
{
xWidth = (int)Math.Floor(((double)image.Width * ((double)sWidth/(double)image.Width)));
xHeight = (int)Math.Floor((double)image.Height * ((double)sHeight/(double)image.Height));
using (Bitmap newImage = new Bitmap(image, xWidth, xHeight))
{
Response.ContentType = "image/Jpeg";
newImage.Save(Response.OutputStream, ImageFormat.Jpeg);
}
}
}
}
}
}
ブラウザにエラーが発生しましたか? – TheGeekYouNeed