Exception:A generic error occurred in GDI+
分析:
一般出现这种问题都是GDI和原数据(比如Bitmap)是同一个实体,只不过是两个引用。换句话说就是这个路径的图片被GDI占用啦。
还有一种情况是路径有问题。
场景一:
WPF的Image控件的Source属性绑定一个图片路径的时候需要吧Bitmap转换成ImageSource。
Bitmap _lastBitmap;public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){if (value != null && System.IO.File.Exists(value.ToString())){if (_lastBitmap != null)_lastBitmap.Dispose();var path = value.ToString();Bitmap bmp = (Bitmap)Bitmap.FromFile(path);_lastBitmap = new Bitmap(bmp.Width, bmp.Height);using (Graphics g = Graphics.FromImage(_lastBitmap)){g.DrawImageUnscaled(bmp, 0, 0);}bmp.Dispose();return PublicMethod.BitMapToImageSource(_lastBitmap);}return null;}
public static ImageSource BitMapToImageSource(Bitmap bmp){BitmapSource returnSource;try{returnSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());}catch{returnSource = null;}return returnSource;}
在Convert的方法里面用到啦Graphics,就是为啦吧图片这个原数据分成两个实体,一个为GDI显示,一个为以后别的操作而用,比如:
保存相同路径的不同图片,需要通知界面更新重新绑定Path对应的图片。Bitmap.Save(“Path”).
场景二:
比如保存的路径为"D:\ my_testfiles \hello.png",中间的目录名字两边存在空格。在实际创建目录的时候是不被允许两边有空格的,但是自己拼接路径的时候难免在两边多个空格。
转载于:https://www.cnblogs.com/kissfu/p/3422829.html
Exception:A generic error occurred in GDI+相关推荐
- A generic error occurred in GDI+的解决方案
转自智慧光原文A generic error occurred in GDI+. 解决方法 使用image1.RotateFlip(RotateFlipType.Rotate90FlipNone)方法 ...
- eclipse突然报错:An internal error occurred during: “Compute launch button tooltip“.并且运行main方法时Run As后面是空
一.报错信息: An internal error occurred during: "Compute launch button tooltip". org.springfram ...
- 安装Tensorflow解决:An HTTP error occurred when trying to retrieve this URL.
目录 问题描述 问题原因 解决方法 问题描述 在Anacoda Prompt中采用命令安装pip install tensorflow,提示: An HTTP error occurred when ...
- MAVEN项目报错:An internal error occurred during: Updating Maven Project java.lang.NullPoint
MAVEN项目报错:An internal error occurred during: "Updating Maven Project" java.lang.NullPoint ...
- Adobe Acrobat DC无法生成pdf:an unexpected error occurred pdfmaker was unable to produce the adobe pdf
在分享笔者解决这个问题的经验之前,首先说一下笔者的结论: 在排除Adobe Acrobat自身软件原因之后,若出现an unexpected error occurred pdfmaker was u ...
- 程序运行报错:A JavaScript error occurred in the main process
找到电脑中的%appdata%文件 在文件夹中,找当出错软件的缓存文件夹, 这里假设出错的是baidu 删除,重启软件,还不行的话,删除软件,然后删除日志文件,再重启电脑,重装软件. 出现A Java ...
- Django - 网页加载报错:A server error occurred. Please contact the administrator(亲测)
1.网页加载时报错显示: 2.pycharm中Terminal报错显示: 如: File "E:\flask_env\django_env\lib\site-packages\django\ ...
- 解决:An HTTP error occurred when trying to retrieve this URL.
一.问题描述 使用Anaconda下载东西时出现的错误.分析原因是:默认使用国外的源下载,出现错误:解决方案是:使用国内的镜像源. 二.问题解决 使用清华镜像源:https://mirrors.tun ...
- yarn安装插件报错: An unexpected error occurred: “https://registry.npmjs.org/vue-router: connect ETIMEDOUT
在安装vue-router的时候,终端报下面的错误 解决方法==>终端输入以下指令:yarn config set sass-binary-site http://npm.taobao.org/ ...
- 解决方法:A fatal error occurred. The required library hostfxr.dll could not be found.
今天在将C#应用程序在另一台电脑上运行时发生标题所示错误 查了一下这应该是VS版本升级导致的问题,原本的应用程序实在VS2019上生成的,没有问题,后来在另外电脑上运行,命令窗口出现这个错误 看了一下 ...
最新文章
- 删除数据 DataIntegrityViolationException: not-null property references a null or transient value解决...
- Py之PIL:不一样的PS之利用PIL库的img.paste方法实现合成刘若英导演电影《后来的我们》海报设计
- How does asp.net web api work?
- GStreamer 的调试工具
- c语言1000内亲密对数,《C语言程序的设计上机指导》项目五函数及其应用.pptx
- caffe 提取特征并可视化(已测试可执行)及在线可视化
- 【Python基础知识-pycharm版】第五节-字典\集合
- 切割照片php上传,php下ajax的文件切割上传
- redis热点key解决方案_缓存穿透,缓存雪崩,4种解决方案分析
- 学习笔记:可持久化线段树(主席树):静态 + 动态
- ltrim函数_数据分析常用Excel函数
- (二)Luence——代码实现索引及搜索
- ffmpeg文档4:创建线程
- passing 'const xxx ' as 'this' argument discards qualifiers [-fpermissive]
- 数据分析师python 城市数据团_城市数据分析师
- BAT、360、今日头条的小程序大战 谁会是最后的赢家?
- Android 免 root 抓包简易教程
- 数仓学习笔记(4)——数仓搭建(ODS层和DIM层)
- 9、图解门禁系统电锁分类及安装方法
- 全国二级计算机c语言试题及答案,全国计算机二级《C语言》预测试题及答案2016...