- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:
我为我弟弟做了一个主页,可以在这里访问:
http://www.daniel-steiger.ch
它在 Linux 上使用 Microsoft ASP.NET MVC3 和 mono 3,通过 fastcgi 和 nginx(加上我自己的 DNS 服务器)。
现在我知道这是一个不寻常的星座,但到目前为止,一切正常。
但是,我遇到了一个非常微妙的小错误。
当在图库中单击缩略图时,我想通过图库 Controller 的 FullImage 方法在新选项卡中显示全尺寸图像。
比如这个直接url:
http://www.daniel-steiger.ch/gallery/FullImage/001.jpg
在 Internet Explorer 中,我得到的图像是文本。
在所有其他浏览器中显示“无效图像”消息。
我通过直接文件 URL 调用图像解决了这个问题,效果很好:
http://www.daniel-steiger.ch/Content/images/gallery/001.jpg?LastWriteTimeUTC=1358694795000
随后,我将这个错误报告给了单声道邮件列表
http://mono.1490590.n4.nabble.com/Bug-in-mono-3-0-1-MVC3-File-FileResult-td4658382.html
现在我得到的回应是,这都是我的错,因为我设置了错误的图像 mime 类型,这是真的。
然而,我发现奇怪的是,如果是这种情况,相同的代码在 Windows 上运行良好,而且像 Chrome 这样的智能浏览器通常会检测到错误的 mime 设置并使用正确的设置。
所以我将 mime-type 从“image/jpg”更改为“image/jpeg”,并将项目重新部署到服务器。
如果图像实际上是 jpeg 图像,我还检查了文件实用程序,确实是。
奇怪的是,它仍然没有显示图像。
在 Internet Explorer 上,我现在得到“不可用”。
在所有其他浏览器上,我得到:图像无法显示,因为它包含错误。
我现在从图像包含错误的 URL 中获取图像。
wget http://www.daniel-steiger.ch/gallery/fullimage/001.jpg
然后我对无效文件和原始文件进行了二进制比较:
cmp -l 001.jpg 001a.jpg | awk '{printf "%08X %02X %02X\n", $1, strtonum(0$2), strtonum(0$3)}' >> comparison.txt
这是比较结果:
让我眼前一亮的是,Internet Explorer 说他找不到的图像实际上有 1.7 MB 大小,并且包含额外的字节:
31 39 36 62 36 38 0D 0A
一开始...
任何人都知道这里出了什么问题/这些字节可能来自哪里(除了它最有可能来自 mono/fastcgi 中的错误这一事实之外)?
顺便说一句,这是新的 Controller 代码:
namespace Homepage.Controllers
{
public class GalleryController : Controller
{
protected static string GetImageDirectory()
{
string bd = AppDomain.CurrentDomain.BaseDirectory;
string strImageDirectory = System.IO.Path.Combine(bd,
"Content");
strImageDirectory =
System.IO.Path.Combine(strImageDirectory, "images");
strImageDirectory =
System.IO.Path.Combine(strImageDirectory, "gallery");
return strImageDirectory;
} // End Function GetImageDirectory
protected static string strImageDirectory = GetImageDirectory();
public FileResult FullImage(string id)
{
string strFileName =
System.IO.Path.Combine(strImageDirectory, id);
//return new FilePathResult("CorrectFullPathAndFileName", "CorrectMime");
//return File(strFileName, "image/jpg"); // Old
return File(strFileName, "image/jpeg"); // New
} // End Action FullImage
public FileResult Thumb(string id)
{
//return Redirect(id);
string strFileName =
System.IO.Path.Combine(strImageDirectory, id);
System.IO.Stream ms =
Tools.Imaging.GetThumbnailStream(strFileName,
System.Drawing.Imaging.ImageFormat.Png);
return File(ms, "image/png");
/*
using (System.IO.Stream ms =
Tools.Imaging.GetThumbnailStream(strFileName,
System.Drawing.Imaging.ImageFormat.Png))
{
return File(ms, "image/png");
}*/
} // End Action Thumb
} // End Class GalleryController : Controller
} // End Namespace Homepage.Controllers
编辑:
它变得陌生:
还有一个带有
0d 0a 0d 0a 30 0d 0a 0d 0a
最后...
我刚刚做了 hexdump,发现原始文件有 filesize(屏住呼吸):
00196b68
这里是十六进制转储(每个 8 MB):
规范格式(hexdump -C 001.jpg > 001.txt):
原始文件:http://www.daniel-steiger.ch/001.txt
拙劣的文件:http://www.daniel-steiger.ch/001a.txt
纯转储 (hexdump 001.jpg > 001_1.txt):
原始文件:http://www.daniel-steiger.ch/001_1.txt
拙劣的文件:http://www.daniel-steiger.ch/001a_1.txt
嗯,恶意文件的十六进制转储是 5 MB,原始文件是 8.2 MB...
我用的是最新稳定的nginx:
sudo -s
nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt-get update
apt-get install nginx
Tools.Imaging 的完整代码(同时将 Tools 重命名为 MvcTools,以匹配程序集命名空间)
using System;
using System.Text;
namespace MvcTools
{
public class Imaging
{
//public static System.Drawing.Size m_sMaxThumbNailDimensions = new System.Drawing.Size(200, 200);
public static System.Drawing.Size m_sMaxThumbNailDimensions = new System.Drawing.Size(300, 300);
public static System.IO.Stream GetImageAsStream(
string strOrgFileName
, System.Drawing.Imaging.ImageFormat ifOutputFormat
)
{
return GetImageAsStream(strOrgFileName, ifOutputFormat, 1024);
} // End Function GetImage
public static System.IO.Stream GetImageAsStream(
string strOrgFileName
,System.Drawing.Imaging.ImageFormat ifOutputFormat
,int rez
)
{
System.IO.MemoryStream ms = null;
if (!System.IO.File.Exists(strOrgFileName))
throw new System.IO.FileNotFoundException(strOrgFileName);
try
{
using (System.Drawing.Image imgSourceImage = System.Drawing.Image.FromFile(strOrgFileName))
{
ms = new System.IO.MemoryStream();
imgSourceImage.Save(ms, ifOutputFormat);
ms.Position = 0;
} // End Using imgSourceImage
} // End Try
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.GetType().ToString());
System.Windows.Forms.MessageBox.Show(ex.Message);
//Response.Write(ex.Message);
} // End Catch
return ms;
} // End Function GetImageAsStream
public static System.Drawing.Size GetThumbnailSize(string strOrgFileName)
{
System.Drawing.Size sThumbNailSizeToUse = new System.Drawing.Size();
try
{
using (System.Drawing.Image imgSourceImage = System.Drawing.Image.FromFile(strOrgFileName))
{
decimal decPixToSubstract = 0;
decimal decPercentage;
if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
{
if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
{
decPercentage = (((decimal)imgSourceImage.Size.Width - (decimal)m_sMaxThumbNailDimensions.Width) / (decimal)imgSourceImage.Size.Width);
decPixToSubstract = decPercentage * imgSourceImage.Size.Height;
sThumbNailSizeToUse.Width = m_sMaxThumbNailDimensions.Width;
sThumbNailSizeToUse.Height = imgSourceImage.Size.Height - (int)decPixToSubstract;
} // End if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
else
{
decPercentage = (((decimal)imgSourceImage.Size.Height - (decimal)m_sMaxThumbNailDimensions.Height) / (decimal)imgSourceImage.Size.Height);
decPixToSubstract = decPercentage * (decimal)imgSourceImage.Size.Width;
sThumbNailSizeToUse.Height = m_sMaxThumbNailDimensions.Height;
sThumbNailSizeToUse.Width = imgSourceImage.Size.Width - (int)decPixToSubstract;
} // End else of if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
} // End if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
else
{
sThumbNailSizeToUse.Width = imgSourceImage.Size.Width;
sThumbNailSizeToUse.Height = imgSourceImage.Size.Height;
} // End else of if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
} // End Using imgSourceImage
} // End Try
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
//Response.Write(ex.Message);
} // End Catch
return sThumbNailSizeToUse;
} // End Sub GetThumbnailSize(string strOrgFileName)
// http://stackoverflow.com/questions/7319842/mvc3-razor-thumbnail-resize-image-ideas
// http://stackoverflow.com/questions/1528525/alternatives-to-system-drawing-for-use-with-asp-net/1528908#1528908
public static void GenerateThumbnailFile(
string strPhysicalPath,
string strOrgFileName, string strThumbnailFileName,
System.Drawing.Imaging.ImageFormat ifOutputFormat, int rez
)
{
try
{
using (System.Drawing.Image imgSourceImage = System.Drawing.Image.FromFile(strOrgFileName))
{
//System.Drawing.Image oImg = System.Drawing.Image.FromStream(fil.InputStream);
decimal decPixToSubstract = 0;
decimal decPercentage;
//default
System.Drawing.Size sThumbNailSizeToUse = new System.Drawing.Size();
if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
{
if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
{
decPercentage = (((decimal)imgSourceImage.Size.Width - (decimal)m_sMaxThumbNailDimensions.Width) / (decimal)imgSourceImage.Size.Width);
decPixToSubstract = decPercentage * imgSourceImage.Size.Height;
sThumbNailSizeToUse.Width = m_sMaxThumbNailDimensions.Width;
sThumbNailSizeToUse.Height = imgSourceImage.Size.Height - (int)decPixToSubstract;
} // End if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
else
{
decPercentage = (((decimal)imgSourceImage.Size.Height - (decimal)m_sMaxThumbNailDimensions.Height) / (decimal)imgSourceImage.Size.Height);
decPixToSubstract = decPercentage * (decimal)imgSourceImage.Size.Width;
sThumbNailSizeToUse.Height = m_sMaxThumbNailDimensions.Height;
sThumbNailSizeToUse.Width = imgSourceImage.Size.Width - (int)decPixToSubstract;
} // End else of if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
} // End if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
else
{
sThumbNailSizeToUse.Width = imgSourceImage.Size.Width;
sThumbNailSizeToUse.Height = imgSourceImage.Size.Height;
} // End else of if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
using (System.Drawing.Bitmap bmpThumbnail = new System.Drawing.Bitmap(sThumbNailSizeToUse.Width, sThumbNailSizeToUse.Height))
{
bmpThumbnail.SetResolution(rez, rez);
using (System.Drawing.Image imgThumbNail = bmpThumbnail)
{
using (System.Drawing.Graphics gGraphicsContext = System.Drawing.Graphics.FromImage(imgThumbNail))
{
gGraphicsContext.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gGraphicsContext.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gGraphicsContext.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
System.Drawing.Rectangle rThumbnailDimension = new System.Drawing.Rectangle(0, 0, sThumbNailSizeToUse.Width, sThumbNailSizeToUse.Height);
gGraphicsContext.DrawImage(imgSourceImage, rThumbnailDimension);
} // End Using gGraphicsContext
imgThumbNail.Save(System.IO.Path.Combine(strPhysicalPath, strThumbnailFileName), ifOutputFormat);
} // End Using imgThumbNail
} // End Using bmpThumbnail
} // End Using imgSourceImage
} // End Try
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
//Response.Write(ex.Message);
} // End Catch
} // End Function GenerateThumbNail
public static System.IO.Stream GetThumbnailStream(
string strOrgFileName
, System.Drawing.Imaging.ImageFormat ifOutputFormat
)
{
return GetThumbnailStream(strOrgFileName, ifOutputFormat, 1024);
} // End Function GetThumbnailStream
public static System.IO.Stream GetThumbnailStream(
string strOrgFileName
,System.Drawing.Imaging.ImageFormat ifOutputFormat
,int rez
)
{
System.IO.MemoryStream ms = null;
try
{
using (System.Drawing.Image imgSourceImage = System.Drawing.Image.FromFile(strOrgFileName))
{
decimal decPixToSubstract = 0;
decimal decPercentage;
System.Drawing.Size sThumbNailSizeToUse = new System.Drawing.Size();
if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
{
if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
{
decPercentage = (((decimal)imgSourceImage.Size.Width - (decimal)m_sMaxThumbNailDimensions.Width) / (decimal)imgSourceImage.Size.Width);
decPixToSubstract = decPercentage * imgSourceImage.Size.Height;
sThumbNailSizeToUse.Width = m_sMaxThumbNailDimensions.Width;
sThumbNailSizeToUse.Height = imgSourceImage.Size.Height - (int)decPixToSubstract;
} // End if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
else
{
decPercentage = (((decimal)imgSourceImage.Size.Height - (decimal)m_sMaxThumbNailDimensions.Height) / (decimal)imgSourceImage.Size.Height);
decPixToSubstract = decPercentage * (decimal)imgSourceImage.Size.Width;
sThumbNailSizeToUse.Height = m_sMaxThumbNailDimensions.Height;
sThumbNailSizeToUse.Width = imgSourceImage.Size.Width - (int)decPixToSubstract;
} // End else of if (imgSourceImage.Size.Width > imgSourceImage.Size.Height)
} // End if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
else
{
sThumbNailSizeToUse.Width = imgSourceImage.Size.Width;
sThumbNailSizeToUse.Height = imgSourceImage.Size.Height;
} // End else of if (m_sMaxThumbNailDimensions.Width < imgSourceImage.Size.Width || m_sMaxThumbNailDimensions.Height < imgSourceImage.Size.Height)
using (System.Drawing.Bitmap bmpThumbnail = new System.Drawing.Bitmap(sThumbNailSizeToUse.Width, sThumbNailSizeToUse.Height))
{
bmpThumbnail.SetResolution(rez, rez);
using (System.Drawing.Image imgThumbNail = bmpThumbnail)
{
using (System.Drawing.Graphics gGraphicsContext = System.Drawing.Graphics.FromImage(imgThumbNail))
{
gGraphicsContext.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gGraphicsContext.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gGraphicsContext.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
System.Drawing.Rectangle rThumbnailDimension = new System.Drawing.Rectangle(0, 0, sThumbNailSizeToUse.Width, sThumbNailSizeToUse.Height);
gGraphicsContext.DrawImage(imgSourceImage, rThumbnailDimension);
ms = new System.IO.MemoryStream();
imgThumbNail.Save(ms, ifOutputFormat);
ms.Position = 0;
} // End Using gGraphicsContext
} // End Using imgThumbNail
} // End Using bmpThumbnail
/*
byte[] buffer = null;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
imgThumbNail.Save(ms, ifOutputFormat);
buffer = ms.ToArray();
}
*/
// Exerts from Page_Load method
//Response.ContentType = "image/" + extension;
//Response.OutputStream.Write(pBuffer, 0, pBuffer.Length);
//Response.End();
//imgThumbNail.Save(System.IO.Path.Combine(strPhysicalPath, strThumbnailFileName), ifOutputFormat);
} // End Using imgSourceImage
} // End Try
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
System.Windows.Forms.MessageBox.Show(ex.Message);
//Response.Write(ex.Message);
} // End Catch
//System.Windows.Forms.MessageBox.Show("image/" + ifOutputFormat.ToString().ToLower());
return ms;
} // End Function GenerateThumbNail
} // End Class Imaging
} // End Namespace Tools
最佳答案
这似乎是一个涉及 Chuncked transfer encoding 的错误在
Class: System.Web.HttpResponse (or one of its dependencies)
Method: TransmitFile(string filename)
编辑:
构造函数中有这段代码:
if (worker_request != null)
use_chunked = (worker_request.GetHttpVersion () == "HTTP/1.1");
修补它以检查 CGI(如果是 CGI,服务器会处理文件传输,因此可能没有根据 RFC 3875 从 FastCGI 服务器返回的分块编码。
internal HttpResponse (HttpWorkerRequest worker_request, HttpContext context) : this ()
{
WorkerRequest = worker_request;
this.context = context;
#if !TARGET_J2EE
if (worker_request != null)
{
if(worker_request.GetHttpVersion () == "HTTP/1.1")
{
string GatewayIface = context.Request.ServerVariables["GATEWAY_INTERFACE"];
use_chunked = (GatewayIface == null || !GatewayIface.StartsWith("CGI"));
}
else
use_chunked = false;
}
#endif
writer = new HttpWriter (this);
}
添加补丁到 https://bugzilla.xamarin.com/show_bug.cgi?id=10001
在 mono 3.2.3 中修复了
关于c# - 为什么图像开头有不需要的额外字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14662795/
我正在尝试学习 Knockout 并尝试创建一个照片 uploader 。我已成功将一些图像存储在数组中。现在我想回帖。在我的 knockout 码(Javascript)中,我这样做: 我在 Jav
我正在使用 php 编写脚本。我的典型问题是如何在 mysql 中添加一个有很多替代文本和图像的问题。想象一下有机化学中具有苯结构的描述。 最有效的方法是什么?据我所知,如果我有一个图像,我可以在数据
我在两个图像之间有一个按钮,我想将按钮居中到图像高度。有人可以帮帮我吗? Entrar
下面的代码示例可以在这里查看 - http://dev.touch-akl.com/celebtrations/ 我一直在尝试做的是在 Canvas 上绘制 2 个图像(发光,然后耀斑。这些图像的链接
请检查此https://jsfiddle.net/rhbwpn19/4/ 图像预览对于第一篇帖子工作正常,但对于其他帖子则不然。 我应该在这里改变什么? function readURL(input)
我对 Canvas 有疑问。我可以用单个图像绘制 Canvas ,但我不能用单独的图像绘制每个 Canvas 。- 如果数据只有一个图像,它工作正常,但数据有多个图像,它不工作你能帮帮我吗? va
我的问题很简单。如何获取 UIImage 的扩展类型?我只能将图像作为 UIImage 而不是它的名称。图像可以是静态的,也可以从手机图库甚至文件路径中获取。如果有人可以为此提供一点帮助,将不胜感激。
我有一个包含 67 个独立路径的 SVG 图像。 是否有任何库/教程可以为每个路径创建单独的光栅图像(例如 PNG),并可能根据路径 ID 命名它们? 最佳答案 谢谢大家。我最终使用了两个答案的组合。
我想将鼠标悬停在一张图片(音乐专辑)上,然后播放一张唱片,所以我希望它向右移动并旋转一点,当它悬停时我希望它恢复正常动画片。它已经可以向右移动,但我无法让它随之旋转。我喜欢让它尽可能简单,因为我不是编
Retina iOS 设备不显示@2X 图像,它显示 1X 图像。 我正在使用 Xcode 4.2.1 Build 4D502,该应用程序的目标是 iOS 5。 我创建了一个测试应用(主/细节)并添加
我正在尝试从头开始以 Angular 实现图像 slider ,并尝试复制 w3school基于图像 slider 。 下面我尝试用 Angular 实现,谁能指导我如何使用 Angular 实现?
我正在尝试获取图像的图像数据,其中 w= 图像宽度,h = 图像高度 for (int i = x; i imageData[pos]>0) //Taking data (here is the pr
我的网页最初通过在 javascript 中动态创建图像填充了大约 1000 个缩略图。由于权限问题,我迁移到 suPHP。现在不用标准 标签本身 我正在通过这个 php 脚本进行检索 $file
我正在尝试将 python opencv 图像转换为 QPixmap。 我按照指示显示Page Link我的代码附在下面 img = cv2.imread('test.png')[:,:,::1]/2
我试图在这个 Repository 中找出语义分割数据集的 NYU-v2 . 我很难理解图像标签是如何存储的。 例如,给定以下图像: 对应的标签图片为: 现在,如果我在 OpenCV 中打开标签图像,
import java.util.Random; class svg{ public static void main(String[] args){ String f="\"
我有一张 8x8 的图片。 (位图 - 可以更改) 我想做的是能够绘制一个形状,给定一个 Path 和 Paint 对象到我的 SurfaceView 上。 目前我所能做的就是用纯色填充形状。我怎样才
要在页面上显示图像,你需要使用源属性(src)。src 指 source 。源属性的值是图像的 URL 地址。 定义图像的语法是: 在浏览器无法载入图像时,替换文本属性告诉读者她们失去的信息。此
**MMEditing是基于PyTorch的图像&视频编辑开源工具箱,支持图像和视频超分辨率(super-resolution)、图像修复(inpainting)、图像抠图(matting)、
我正在尝试通过资源文件将图像插入到我的程序中,如下所示: green.png other files 当我尝试使用 QImage 或 QPixm
我是一名优秀的程序员,十分优秀!