- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 winform C# 桌面应用程序。
我不断收到 jpeg 文件。我正在将当前图像与之前的 1 进行比较。通过使用第 3 方工具 - Emgu - 我可以创建一个仅包含差异的新图像。
然后我将该图像转换为内存流,然后再转换为字节数组。
在接收应用程序中,我使用这个字节数组并使用这些字节通过内存流加载图像。
问题是图像质量下降了很多。
如果在客户端将图像转换为内存流之前将图像保存到硬盘驱动器,则图像质量很好。
问题出在我将它作为内存流加载时。
我将其编码为 jpeg。
如果我在将其发送到服务器之前将其编码为 PNG,那么质量又会很好。将字节数组中的大小编码为 PNG 的问题会激增。
我的意图一直是减少我必须上传的字节数以缩短响应时间。
我是做错了什么还是不能这样做?
这是我的代码:
Bitmap imgContainingDifference
= GetDiffFromEmgu(CurrentJpegImage, PreviousJpegImage);
using (System.IO.MemoryStream msIn = new System.IO.MemoryStream())
{
holding.Save(msIn, System.Drawing.Imaging.ImageFormat.Jpeg);
data = msIn.ToArray();
}
//test here
using (System.IO.MemoryStream msOut = new System.IO.MemoryStream(_data))
{
Bitmap testIMG = (Bitmap)Image.FromStream(msOut);
}
//result is image is poor/degrades
如果我这样做:
using (System.IO.MemoryStream msIn = new System.IO.MemoryStream())
{
holding.Save(msIn, System.Drawing.Imaging.ImageFormat.Png);
data = msIn.ToArray();
}
using (System.IO.MemoryStream msOut = new System.IO.MemoryStream(_data))
{
Bitmap testIMG = (Bitmap)Image.FromStream(msOut);
}
//Image is good BUT the size of the byte array is
//10 times the size of the CurrentFrame right at the start.
这是使用以下 child 建议时图像的样子:
我现在已经尝试使用来自@MagnatLU 的友好建议的编码器,如果我使用 FreeImage.Net,我也可以获得相同质量的图像。
最佳答案
你可以设置JPEG compression level将文件编码为质量和大小之间最佳经验权衡的值。
关于c# - 保持图像质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20167206/
我正在尝试在特定图像上添加文本。它工作完美,但图像质量较低,尤其是 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 (图片列表) 我
我是一名优秀的程序员,十分优秀!