当前位置:网站首页>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 foreign key constraint
- 【openh264】cmake: msopenh264-static
- Machine learning - linear regression
- At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
- Chapter III project schedule management of information system project manager summary
- Good simple recursive problem, string recursive training
- Jupyter notebook crawling web pages
- Where, on when MySQL external connection is used
- MySQL external connection, internal connection, self connection, natural connection, cross connection
- SQLyog的基本使用
猜你喜欢
MySQL external connection, internal connection, self connection, natural connection, cross connection
SQLyog的基本使用
Nacos source code startup error report solution
多线程基本概念(并发与并行、线程与进程)和入门案例
看板快速启动指南
Deep learning notes - semantic segmentation and data sets
Publish your own wheel - pypi packaging upload practice
Define defines constants and macros, pointers and structures
直播带货表格模板-自动显示图片-自动关联系列商品
What are the redis data types
随机推荐
学习笔记:Unity CustomSRP-13-ColorGrading
Barcode generation and decoding, QR code generation and decoding
The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose
What are the redis data types
#define 定义常量和宏,指针和结构体
Installing kuberneters using kubedm
Luogu p2731 horse riding fence repair
使用 Kears 实现ResNet-34 CNN
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
机器学习---线性回归
The WebService interface writes and publishes calls to the WebService interface (2)
Day.js 常用方法
数字化转型失败,有哪些原因?
MySQL slow query
Tensorflow realizes web face login system
Golang select priority execution
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
Deep learning notes - semantic segmentation and data sets
DevOps生命周期,你想知道的全都在这里了!
Semi synchronous replication of MariaDB