当前位置:网站首页>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
边栏推荐
- MySQL views the SQL statement details executed by the optimizer
- Flip coin (Blue Bridge Cup)
- 多线程基本概念(并发与并行、线程与进程)和入门案例
- scp命令详解
- 数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
- Mairadb数据库基本操作之数据管理
- Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?
- #define 定义常量和宏,指针和结构体
- Semi synchronous replication of MariaDB
- 【openh264】cmake: msopenh264-static
猜你喜欢

2021-09-23

Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases

Blender程序化地形制作

2022/4/22

项目经理值得一试的思维方式:项目成功方程式

数字化转型失败,有哪些原因?

Routing parameters

PIP free export with path (@ file: / / /) notes

Power consumption parameters of Jinbei household mute box series

我这位老程序员对时代危险和机遇的一点感悟?
随机推荐
Minimum spanning tree -- unblocked project hdu1863
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
Data management of basic operation of mairadb database
MySQL memo (for your own query)
On distributed lock
学习笔记:Unity CustomSRP-11-Post Processing---Bloom
Unity C e-learning (IV)
项目经理值得一试的思维方式:项目成功方程式
The WebService interface writes and publishes calls to the WebService interface (2)
Deep learning notes - semantic segmentation and data sets
MySQL foreign key constraint
2022年最热门的招聘技术技能是什么,您绝对想不到
Let the LAN group use the remote device
Golang memory escape
Live delivery form template - automatically display pictures - automatically associate series products
学习笔记:Unity CustomSRP-12-HDR
Knowledge points sorting: ES6
看板快速启动指南
Harmonious dormitory (linear DP / interval DP)
Good simple recursive problem, string recursive training