我将JPG图片保存至数据库: MemoryStream ms = new MemoryStream();
pictureBox.Image.Save(ms,ImageFormat.Jpeg);在运行到 "pictureBox.Image.Save(ms,ImageFormat.Jpeg);"时,系统报错:
“c# A generic error occurred in GDI+.”请问是什么原因(换成bmp,gif等格式也不行)?
pictureBox.Image.Save(ms,ImageFormat.Jpeg);在运行到 "pictureBox.Image.Save(ms,ImageFormat.Jpeg);"时,系统报错:
“c# A generic error occurred in GDI+.”请问是什么原因(换成bmp,gif等格式也不行)?
解决方案 »
- sql 使用getdate()获取的时间做主键出现问题
- 【不懂就问】Linq会不会比循环来的好?
- [求助]我是新手.对C#感兴趣.问各位前辈一些问题
- 如何实现这样的Datagrid功能
- VS打包以后为什么不能自动检测到自带的dotnetfx.exe并安装
- 单击一个按钮
- 如何将整个XML文件加密?而不是只加密当中的元素值.
- 新手请教CheckedListBox的绑定问题
- 【高分】求c#特效界面!!!
- ListView中的图标需要连接ImageList,有什么方式可以不连接ImageList或者可以更改ImageList的内容?
- 问题1
- 急~~~~~HttpWebRequest.Connection的问题
2、确认你是否有权限读写图片所在的文件夹。
3、http://www.eggheadcafe.com/aspnet_answers/NETFrameworkdrawing/Jan2006/post25815576.aspI found the problem: I was reading the image from the database using a
memorystream object to convert it from an array of bytes to a bitmap. The
memory stream object then was destroyed and hence the GDI+ specialty that
the creating stream must live as long as the bitmap was violated. --> That's
why I got the GDI+ error when trying to convert the same bitmap again later
to Base64.
Solution: use an object variable for the memorystream to ensure it lives as
long as the bitmap object itself, actually I am recycling it to convert the
image back to Base64
Let's see if the converted image is still good :)
Martin
pictureBox.Image.Save(ms,ImageFormat.Jpeg);
方法来获取数据。相应的替换方法是
方法一、通过抓屏,形成Bitmap对象,然后再调用Bitmap.Save方法获得图像数据;方法二、给PictureBox初始化Image对象,所有操作也通过Image对象完成,这样你在通过pictureBox.Image.Save的时候不会出错。
pictureBox.Image.Save(ms,server.path("")+"\\ImageFormat.Jpeg");
MemoryStream ms = new MemoryStream();
pictureBox.Image.Save(ms,server.path("")+"\\ImageFormat.Jpeg");
再做pictureBox.Image.Save(ms,ImageFormat.Jpeg)就可以了