解决A generic error occurred in GDI+的问题
来源:互联网 发布:编程实现一个冒泡排序 编辑:程序博客网 时间:2024/05/29 07:27
DNN Fck editor中的上传图片没有改变size的功能感觉很不方便,所以准备加一个改变图像size的功能。
因为不想改变UploadFile()这个DNN core method所以准备只是改动了fck editor 上传的页面
改动后的工作流程是:
1. 选择图片上传,调用DNN UploadFile()上传图片
2. 读取上传到server的file 另存为一个临时的Image
3. 调用GDI+ GetThumbnailImage改变Image尺寸覆盖原来的文件
问题随之而来,出现在第三步上运行到存储的时候总是 出现A generic error occurred in GDI+
最后发现原因是:
To retain access to the source bits, GDI+ locks any source file, and forces the application to maintain the life of any source stream, for the life of the Bitmap or the Image object.
解决的方法是创建Index or Non-Indexed Image , 用Graphics.DrawImage() 来copy Image到一个新建立的Bitmap 对象然后多这个新的Image 执行Resize
Sample Code:
1Bitmap bm1=(Bitmap)Image.FromFile("doodaa.gif");
2Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
3Graphics g=Graphics.FromImage(bm2);
4g.DrawImageUnscaled(bm1,0,0);
5//bm2 now contains a non-indexed version of the image.
6//Now draw the X..
7g.DrawLine(blah-blah.);
8g.DrawLine(blah-blah.);
9//get rid of the graphics
10g.Dispose();
11//and save a new gif
12bm2.Save("foobar.gif",ImageFormat.Gif);
13
2Bitmap bm2=new Bitmap(bm1.Width,bm1.Height);
3Graphics g=Graphics.FromImage(bm2);
4g.DrawImageUnscaled(bm1,0,0);
5//bm2 now contains a non-indexed version of the image.
6//Now draw the X..
7g.DrawLine(blah-blah.);
8g.DrawLine(blah-blah.);
9//get rid of the graphics
10g.Dispose();
11//and save a new gif
12bm2.Save("foobar.gif",ImageFormat.Gif);
13
这里是微软的KB对这个问题的叙述:
http://support.microsoft.com/?id=814675
阅读全文
0 0
- 解决A generic error occurred in GDI+的问题
- 解决A generic error occurred in GDI+的问题
- 有关A generic error occurred in GDI+问题
- A generic error occurred in GDI+问题对应~
- A generic error occurred in GDI+. 解决方法
- 异常A generic error occurred in GDI+的解决办法
- System.Drawing.Image.Save, A generic error occurred in GDI+.
- 图片处理报异常,A generic error occurred in GDI+
- 安装完win7+Ubuntu双系统,无法进入Win7,A read disk error occurred问题的解决
- 安装完win7+Ubuntu双系统,无法进入Win7,A read disk error occurred问题的解决
- nginx报A error occurred错误的解决过程
- nginx报A error occurred错误的解决过程
- 解决使用Genymotion的Unknown generic error问题
- 解决SOAPTest “error occurred during initialization of vm”的问题
- IAR出现An error occurred while retrieving GDI features: gdi-error [40201]的解决方法
- error could not create the java virtual machine.error:a fatal exception has occurred...问题之解决
- AN ERROR OCCURRED IN A TRIGGERED SQL -723
- 解决 Flex4 Error in Module 的问题
- 日期插件layDate的使用
- 教你五招:防御互联网最可怕搜索Shodan
- 水仙花数C++
- cocos2d-js下的热更新机制
- Markdown学习
- 解决A generic error occurred in GDI+的问题
- NOIP 冲刺:常见的递推之第二类斯特林数
- eclipse报内存溢出
- 乐观锁与悲观锁
- 我的机器学习之路(三)
- [App] OpenVPN 2.3.14 搭建
- Word中插入表格与柱状图饼状图技术经验分享
- webpack+vue初始化项目基本
- Matlab 自定义自己的 colormap(注意其中的一个坑)