- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
拍摄以下两张图片:
开发版 - IIS7 Windows 7 Pro 64 位机器
实时版本 - IIS7 Windows Server 2008 64 位机器
请注意 Live 版本是如何“像素化”的并且看起来质量很低,而 Dev 版本是平滑的、抗锯齿的并且看起来不错。这些都是由相同的代码生成的:
' Settings
Dim MaxHeight As Integer = 140
Dim MaxWidth As Integer = 140
Dim WorkingFolderPath As String = "\\server\share\bla\"
Dim AllowedFileExtensions As New ArrayList
AllowedFileExtensions.Add(".jpg")
AllowedFileExtensions.Add(".jpeg")
' Select an image to use from the WorkingFolder
Dim ImageFileName As String = ""
Dim WorkingFolder As New IO.DirectoryInfo(WorkingFolderPath)
Dim SourceImages As IO.FileInfo() = WorkingFolder.GetFiles()
For Each SourceImage As IO.FileInfo In SourceImages
If AllowedFileExtensions.Contains(SourceImage.Extension.ToLower) = True Then
ImageFileName = SourceImage.Name
End If
Next
' Determine path to selected image (if no image was found use a placeholder)
Dim PhysicalPath As String = ""
If ImageFileName = "" Then
' No Image was found, use the filler image
PhysicalPath = Server.MapPath("ProductOfTheMonthMissing.jpg")
Else
' An Image was found, Redirect to it / build path for Thumnailing
If Request.QueryString("FullSize") = "true" Then
Response.Redirect("../share/bla/" & ImageFileName)
Else
PhysicalPath = WorkingFolderPath & ImageFileName
End If
End If
' Load image and output in binary (resizing if necessary)
Using ProductImage As System.Drawing.Image = System.Drawing.Image.FromFile(PhysicalPath)
Dim newWidth As Integer = ProductImage.Width
Dim newHeight As Integer = ProductImage.Height
' Check if selected size is too big, if so, determine new size
If ProductImage.Width > MaxWidth Or ProductImage.Height > MaxHeight Then
Dim ratioX As Double = CDbl(MaxWidth) / ProductImage.Width
Dim ratioY As Double = CDbl(MaxHeight) / ProductImage.Height
Dim ratio As Double = Math.Min(ratioX, ratioY)
newWidth = CInt(ProductImage.Width * ratio)
newHeight = CInt(ProductImage.Height * ratio)
End If
' Create a new bitmap from the image with new size
Dim Codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
Dim CodecInfo As ImageCodecInfo = Nothing
Dim ProductOfTheMonth As New Bitmap(ProductImage, newWidth, newHeight)
Dim ReSizer As Graphics = Graphics.FromImage(ProductOfTheMonth)
ReSizer.InterpolationMode = InterpolationMode.HighQualityBicubic
ReSizer.SmoothingMode = SmoothingMode.HighQuality
ReSizer.PixelOffsetMode = PixelOffsetMode.HighQuality
ReSizer.CompositingQuality = CompositingQuality.HighQuality
' Ensure the encoder uses the best quality settings
Dim EncoderParams As New EncoderParameters(3)
EncoderParams.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L)
EncoderParams.Param(1) = New EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, CInt(EncoderValue.ScanMethodInterlaced))
EncoderParams.Param(2) = New EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, CInt(EncoderValue.RenderProgressive))
' Set jpeg as the output codec
For Each Codec As ImageCodecInfo In Codecs
If Codec.MimeType = "image/jpeg" Then
CodecInfo = Codec
End If
Next
' Ready a memory stream and byte array
Dim MemStream As New MemoryStream()
Dim bmpBytes As Byte()
' Save the image the the memory stream & prep ContentType for HTTP reasponse
Response.ContentType = "image/jpeg"
ProductOfTheMonth.Save(MemStream, CodecInfo, EncoderParams)
' Flush memory stream into byte array & flush to browser
bmpBytes = MemStream.GetBuffer()
Response.BinaryWrite(bmpBytes)
' Cleanup
ProductOfTheMonth.Dispose()
MemStream.Close()
ProductImage.Dispose()
End Using
最佳答案
我已经和,在这里回答了一个类似的问题:Graphics wrong image interpolation in .Net ,但简而言之,似乎不同的平台使用不同的内部算法(或者它可能是 GDI 中的内部舍入问题)。
无论如何,问题出在设置上。因此,请尝试以下操作:
Using s As Bitmap = DirectCast(Bitmap.FromFile(PhysicalPath), Bitmap)
Dim scale As Double = Math.Min(140.0 / s.Width, 140.0 / s.Height)
Using d As New Bitmap(CInt(Math.Floor(scale * s.Width)), CInt(Math.Floor(scale * s.Height)), System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Using dg As Graphics = Graphics.FromImage(d)
dg.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
dg.SmoothingMode = SmoothingMode.HighQuality
dg.PixelOffsetMode = PixelOffsetMode.HighQuality
dg.CompositingQuality = CompositingQuality.HighQuality
dg.Clear(Color.White)
dg.DrawImage(s, New Rectangle(0, 0, d.Width, d.Height), New Rectangle(0, 0, s.Width, s.Height), GraphicsUnit.Pixel)
End Using
Dim jpegArgs As New EncoderParameters(3)
jpegArgs.Param(0) = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L)
jpegArgs.Param(1) = New EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, CInt(EncoderValue.ScanMethodInterlaced))
jpegArgs.Param(2) = New EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, CInt(EncoderValue.RenderProgressive))
Dim Codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
Dim jpegParams As ImageCodecInfo = Nothing
'#### Set jpeg as the output codec
For Each Codec As ImageCodecInfo In Codecs
If Codec.MimeType = "image/jpeg" Then
jpegParams = Codec
End If
Next
Response.Clear()
Response.ContentType = "image/jpeg"
d.Save(Response.OutputStream, jpegParams, jpegArgs)
End Using
End Using
关于.net - 相同的代码在不同的服务器上产生不一致的图像质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20069100/
我正在尝试在特定图像上添加文本。它工作完美,但图像质量较低,尤其是 papyrus.ttf 字体。如何提高图像中文本的质量。但我需要高质量来打印输出。这是我的代码..它非常简单。 header("Co
是否可以获得现有图像的当前质量? 我想加载一个 JPEG 并在不改变质量和 DPI 的情况下再次保存它。 (我需要在保存前做一些像素操作) 最佳答案 JPEG 是一种有损格式。 这样做的直接方式,读取
我正在构建一个标签打印机。它由一个标志和一些文字组成,并不难。我已经花了 3 天时间尝试将原始 SVG Logo 绘制到屏幕上,但 SVG 太复杂,使用了太多渐变等。 所以我有一个高质量的位图 Log
我正在尝试以最快的方式以编程方式降低图像质量。现在,我能够从 byte[] 读取图像,然后作为 MemoryStream 将其读取到 Bitmap 并通过 Drawing。 Imaging.Encod
我允许用户上传图片。但是,我想保持 JPEG 质量不超过 90%。我打算做的是检测当前质量:- 如果少于 90% 什么都不做- 如果超过 90%,则使用 Image Magick 将图像重新压缩到 9
我正在制作一个 Android 应用程序,该应用程序通过使用内置摄像头作为 Intent 来使用摄像头。我正在逐个像素地对照片进行一些分析。我的 wildfire 在普通照片中返回 79000 像素,
我正在使用 python 程序生成一些数据,使用 matplotlib.pyplot 绘制数据,然后将图形显示在 latex 文件中。 我目前正在将图形保存为 .png 文件,但图像质量不是很好。我试
一直在尝试通过应用引擎将以下 png 文件上传到谷歌云存储: 在上传之前,我通过 PIL 运行它来处理任何图像旋转或背景颜色变化等 但是,即使在 python 命令行中运行相同的命令结果很好,但通过应
给定以下 Image 对象(它位于 ListView 对象的 DataTemplate 中): 我应该如何获得高质量的双三次插值图像? (在屏幕上,此图像的大小小于源 PNG,但默认调整大小似乎
如何在 PHP5 中压缩 GIF 图像文件? 我知道可以像这样处理 JPG imagejpeg($resource, $filename, $quality)根据 http://us.php.net/
我使用 html5 Canvas 元素在我的浏览器中调整图像大小。事实证明,质量非常低。我发现了这个:Disable Interpolation when Scaling a 但这无助于提高质量。 下
我正在使用 Visual Studio 2019 构建带有自定义任务 Pane 的 Excel 插件。 在用作自定义任务 Pane 的用户控件中,我添加了 imlNavigation (图片列表) 我
我是一名优秀的程序员,十分优秀!