如何在 C# 中将位图对象保存为 jpeg 文件

发布于 2024-12-21 14:16:42 字数 1428 浏览 1 评论 0原文

我有一个返回位图对象的函数。如何在 C# 中将这样的对象保存为 jpg 文件?

到目前为止,我有这个代码段

b = MakeGrayscale(b);
b.Save("C:\\test.jpg");

,我收到此错误消息

{“GDI+ 中发生一般错误。”}

StackTrace

   at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(String filename, ImageFormat format)
   at System.Drawing.Image.Save(String filename)
   at Convert.Program.Plot(Byte[]& fileBufferArray, Int32 fileSize, Int32 offset) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\Convert\Convert\Program.cs:line 151
   at Convert.Program.Main(String[] args) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\Convert\Convert\Program.cs:line 42
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

有人可以帮助我吗?

I have a function that returns a bitmap object. How do i save such a object as a jpg file in C# ?

So far i have this code segment

b = MakeGrayscale(b);
b.Save("C:\\test.jpg");

I get this error message

{"A generic error occurred in GDI+."}

StackTrace

   at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(String filename, ImageFormat format)
   at System.Drawing.Image.Save(String filename)
   at Convert.Program.Plot(Byte[]& fileBufferArray, Int32 fileSize, Int32 offset) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\Convert\Convert\Program.cs:line 151
   at Convert.Program.Main(String[] args) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\Convert\Convert\Program.cs:line 42
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Could someone please help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文