使用 QImage (qt) 生成文本图像
我正在尝试使用 QImage 从文本创建图像。
根据此处的文档: http://doc.qt.io/qt-5/qimage.html #Format-enum
我们不能将 QImage::Format_Indexed8
与 QImage 一起使用。 我无法使用 QImage::Format_Mono
或 QImage::Format_MonoLSB
由于其质量较低。
我的问题是:
- 创建文本图像(批处理)的最佳方法是什么 我们可以用最小的文件大小获得不错的质量吗?
- 有没有办法在创建图像后通过QT进行图像压缩以减小文件大小?
I am trying to create images from text using QImage.
As per the documentation here:
http://doc.qt.io/qt-5/qimage.html#Format-enum
We cannot use QImage::Format_Indexed8
with QImage.
I cannot use QImage::Format_Mono
or QImage::Format_MonoLSB
due to its low quality.
My question is:
- What is the best way to create textual image (batch processing) so
that we can get decent quality with minimum file size? - Is there is any way to do image compression through QT once the image is created to reduce the file size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是执行此操作的示例代码:
它创建此图像:
输出格式为 PNG,因此它将具有良好的压缩效果而不会损失任何质量。
Here is a sample code that does it:
It creates this image:
The output format is PNG, so it will have good compression without losing any quality.
这个例子向您展示了如何使用 QPainter::drawText 并使用字体:
http://doc.qt.io/archives/qt-4.7/painting-fontsampler.html
QImage::save
支持多种格式和质量级别:http://doc.qt.io/archives/qt-4.7/qimage.html#reading-and-writing-image-files
虽然
QImage
在QtCore中,QPainter
和文本绘制例程位于 QtGUI 中。因此,在 Linux 系统上,这需要运行 X 服务器:http: //www.qtcentre.org/threads/1758-QPainter-in-console-apps
There's this example, which shows you how to use
QPainter::drawText
and work with fonts:http://doc.qt.io/archives/qt-4.7/painting-fontsampler.html
QImage::save
has support for a variety of formats and quality levels:http://doc.qt.io/archives/qt-4.7/qimage.html#reading-and-writing-image-files
Although
QImage
is in QtCore,QPainter
and the text drawing routines are in QtGUI. So on a Linux system this will require an X server to be running:http://www.qtcentre.org/threads/1758-QPainter-in-console-apps