当前位置:网站首页>Graphics.FromImage报错“Graphics object cannot be created from an image that has an indexed pixel ...”
Graphics.FromImage报错“Graphics object cannot be created from an image that has an indexed pixel ...”
2022-04-23 05:16:00 【gc_2299】
测试OCR模块PaddleSharp过程中,为了在图片中绘制出包含文本块的矩形,用Graphics.FromImage函数获取图片的绘图对象。使用之前文章中的图片测试时,jpg图片可以正常绘制,但是测试参考文献1中png格式的身份证图片时,程序报如下错误:
A Graphics object cannot be created from an image that has an indexed pixel format. (Parameter ‘image’)
从MSDN中看到,调用Graphics.FromImage函数时存在例外,图片具有索引像素格式或格式未定义时会抛异常,本文遇到的错误中提到的indexed pixel即索引像素,因此应该是测试的图片格式不支持Graphics.FromImage。

参考文献3介绍了索引像素格式图片,其常见格式为gif和png,主要目的是降低图片大小。参考文献4中给出了索引像素格式图片创建Graphics对象的常见处理方式,即将图片复制到另外的Bitmap对象后再使用 Graphics。
对于本文的问题,可以采用两种方式,一种是通过程序方式将png图片转换为bmp或jpg格式后再绘制包含文本块的矩形,另一种是手动将图片另存为jpg或bmp格式。
由于测试图片中报错的只有一个图片,简单起见,直接用画图板将其另存为jpg,再运行程序,即可正常创建Graphics对象并绘制包含文本块的矩形,效果图下图所示(测试图形来源于参考文献1)。

参考文献:
[1]http://news.sohu.com/a/524033869_121124363
[2]https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.graphics.fromimage?redirectedfrom=MSDN&view=dotnet-plat-ext-6.0#System_Drawing_Graphics_FromImage_System_Drawing_Image_
[3]https://wenku.baidu.com/view/9db4726b757f5acfa1c7aa00b52acfc789eb9f99.html
[4]https://blog.csdn.net/w6579106/article/details/115865396
版权声明
本文为[gc_2299]所创,转载请带上原文链接,感谢
https://blog.csdn.net/gc_2299/article/details/124309014
边栏推荐
- Detailed explanation of hregionserver
- Summary of R & D technology
- Interesting prime number problem hdu5750
- 数字化转型失败,有哪些原因?
- TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
- 学习笔记:Unity CustomSRP-12-HDR
- mariadb数据库的主从复制
- Summary of MySQL knowledge points
- At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
- MySQL memo (for your own query)
猜你喜欢

Power consumption parameters of Jinbei household mute box series

Basic use of sqlyog

深度学习笔记 —— 数据增广

Solution of how to log in with mobile phone verification code in wireless network

Traversal of tree

2021-09-23

The 8 diagrams let you see the execution sequence of async / await and promise step by step

SQLyog的基本使用

Servlet3 0 + event driven for high performance long polling

#define 定义常量和宏,指针和结构体
随机推荐
Chapter I overall project management of information system project manager summary
Restful toolkit of idea plug-in
了解 DevOps,必读这十本书!
JS Array常见方法
Unity C e-learning (IV)
Using MySQL with Oracle
MySQL views the SQL statement details executed by the optimizer
如何在Word中添加漂亮的代码块 | 很全的方法整理和比较
Simple application of parallel search set (red alarm)
Golang memory escape
Various ways of writing timed tasks of small programs
深度学习笔记 —— 微调
Machine learning - linear regression
即将毕业的大学生找技术开发工作的焦虑根源
The WebService interface writes and publishes calls to the WebService interface (2)
Routing parameters
Implementation of resnet-34 CNN with kears
Flip coin (Blue Bridge Cup)
Day.js 常用方法
Golang select priority execution