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:

2

3

4

5

6

7


8


9

10

11

12

13

这里是微软的KB对这个问题的叙述:
http://support.microsoft.com/?id=814675