C# .NET 将 JPEG 图像转换为位图结构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/380604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 01:18:38  来源:igfitidea点击:

C# .NET Convert a JPEG Image into a Bitmap structure

c#.netjpeg

提问by asdrubael

I have a JPEG "image" (actually a BLOB in a database) which I want to import/convert into a "Bitmap" structure in memory. The reason is that I use a third party library which is unable to work with JPEG images and I need to pass an uncompressed bitmap (as a pointer). All I found so far are ways to convert between different formats on disk but saving the image as bitmap first and re-import it will take far too long.

我有一个 JPEG“图像”(实际上是数据库中的一个 BLOB),我想将其导入/转换为内存中的“位图”结构。原因是我使用的第三方库无法处理 JPEG 图像,我需要传递未压缩的位图(作为指针)。到目前为止,我发现的只是在磁盘上的不同格式之间进行转换的方法,但首先将图像保存为位图并重新导入它会花费很长时间。

I don't know much about .NET but I think a System.Drawing.Bitmap should be able to hold the uncompressed data. I'm working with C# and Visual Studio 2008.

我对 .NET 了解不多,但我认为 System.Drawing.Bitmap 应该能够保存未压缩的数据。我正在使用 C# 和 Visual Studio 2008。

采纳答案by Mehrdad Afshari

// blob is a byte[] retrieved from DB
Bitmap bmp = new Bitmap(new MemoryStream(blob));