我有一个应用程序,它使用移动摄像头捕获的图像并将其发送到网络服务。目前我将图像放入 byte[] 中,然后将其传输。这是通过以下方式完成的:
filename = cameracapturedialog.FileName;
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] ImageByte = new byte[fs.Length]; //file to send
fs.Read(ImageByte, 0, Convert.ToInt32(fs.Length));
但现在我想执行一些处理(调整大小),因此我必须将图像放入 BITMAP 对象中,处理后我会将其转换回 JPEG。
有没有办法将 JPEG 转换为位图,然后再转换回 JPEG,而不改变像素(为了测试,我将不对位图执行任何处理)?因此,如果我将第一个 JPEG 与第二个 JPEG 进行比较,我需要文件完全相同。
您认为最好的解决方案是什么?我可以使用其他东西来代替位图吗?任何有关代码的建议将不胜感激。
I have an application that use the image captured by the mobile camera and sends it to a webservice. Currently I am putting the image in a byte[] which then will be transmitted. This is done by:
filename = cameracapturedialog.FileName;
FileStream fs = new FileStream(filename, FileMode.Open);
byte[] ImageByte = new byte[fs.Length]; //file to send
fs.Read(ImageByte, 0, Convert.ToInt32(fs.Length));
But now I would like to perform some processing (resizing), hence I had to put the image into a BITMAP object, and after the processing I will convert it back to JPEG.
Is there a way to convert a JPEG into Bitmap and then back to JPEG without having no changes in the pixels (for testing I will perform no processing on the Bitmap)? Hence if I compare the first JPEG with the second JPEG I need that the files will be exactly the same.
What do you think the best solution is? Can I use something else instead of Bitmap. Any suggestion with some code will be greatly appreciated.
发布评论
评论(2)
JPG 是一种有损格式。由于编码算法的工作方式,它总是会丢失信息。因此,无论您使用什么编码器,您都永远无法从 jpg 中获得原始图像。
JPG is a lossy format. It will ALWAYS lose information because of the way the encoding algorithm works. So you'll never get the original image from a jpg, no matter what encoder you use.
不。您可以使用 Quality=100 保存它,这几乎就像原始图像一样。但是,生成的文件将巨大。
No. You can save it with Quality=100 which would be almost like the original image. However, the resulting file will be huge.