bmp qimage 保存位_在Qt中保存QImage(Save a QImage in Qt)

在Qt中保存QImage(Save a QImage in Qt)

是否可以导出Qt创建者生成的图像? qimage是Qt中内置的数据类型。 我们使用setpixel()函数修改它。 我想保存该图像以供进一步使用。

Is it possible to export images generated in Qt creator? The qimage which is a built in data type in Qt. We modify it using setpixel() function. I want to save that image for further use.

原文:https://stackoverflow.com/questions/27958716

2019-06-06 11:06

满意答案

您可以使用

bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const

保存你的QImage

使用给定的图像文件格式和品质因数将图像保存到具有给定fileName的文件。 如果format为0,QImage将尝试通过查看fileName的后缀来猜测格式。

品质因数必须在0到100或-1的范围内。 指定0以获取小型压缩文件,指定100表示​​大型未压缩文件,使用-1(默认值)使用默认设置。

如果图像成功保存,则返回true; 否则返回false。

You can use

bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const

To save your QImage

Saves the image to the file with the given fileName, using the given image file format and quality factor. If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.

The quality factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.

Returns true if the image was successfully saved; otherwise returns false.

2015-01-15

相关问答

您可以使用 bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const

保存你的QImage 使用给定的图像文件格式和品质因数将图像保存到具有给定fileName的文件。 如果format为0,QImage将尝试通过查看fileName的后缀来猜测格式。 品质因数必须在0到100或-1的范围内。 指定0以获取小型压缩文件,指定100表示大型未压缩文件,使用-1(默认...

显示如何显示QImage的简单但完整的示例可能如下所示: #include

#include

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

QImage myImage;

myImage.load("test.png");

QLabel myLabel;

myLabel.setPixmap(QPixmap::fro...

从QImage文档: 因为QImage是QPaintDevice子类,所以可以使用QPainter直接绘制到图像上。 在QImage上使用QPainter时,可以在除当前GUI线程之外的另一个线程中执行绘制。 只需在您的图像上创建一个QPainter并绘制您需要的内容。 From documentation of QImage: Because QImage is a QPaintDevice subclass, QPainter can be used to draw directly onto...

确保您没有使用有损格式(例如JPEG)进行保存。 Make sure you're not saving using a lossy format, such as JPEG.

事实证明,在将图像保存到bmp之前,Qt强制转换图像。 qt-src / src / gui / image / qbmphandler.cpp:777 : bool QBmpHandler::write(const QImage &img)

{

QImage image;

switch (img.format()) {

case QImage::Format_ARGB8565_Premultiplied:

case QImage::Format_ARGB8555_...

来自QImage::QImage(int width, int height, Format format)的文档QImage::QImage(int width, int height, Format format) : 警告:这将创建一个包含未初始化数据的QImage。 在使用QPainter绘制图像之前,调用fill()以使用适当的像素值填充图像。 因此,在构建图像后,请在图像上调用QImage::fill(uint pixelValue) 。 From the docs for QImag...

我用这种方式解决了这个问题: //This WON'T WORK due to problems caused by presence of OpenCV library; it interferes with normal QImage loading from QResources

/*

QImage logoImage(":/images/Logo.png");

*/

//Read file rawly into RAM (workaround to OpenCV/QImage issue)...

谢谢切尔诺贝利! 我偶然得到了解决方案。 我在我的完整程序中尝试了测试代码并且运行良好。 这是因为PyQt的很多功能必须在使用它之前构造一个QGuiApplication 。 from PyQt5 import QtCore, QtGui, QtWidgets

import sys

app = QtWidgets.QApplication(sys.argv)

print(QtGui.QImageWriter.supportedImageFormats())

现在我们得到了完整支持的格式: [Py...

我会尝试这样的事情(即,加载图像,创建相同大小的另一个图像,绘制背景,绘制图像): QImage image1("someFile.png");

QImage image2(image1.size());

image2.fill(QColor(Qt::white).rgb());

QPainter painter(&image2);

painter.drawImage(0, 0, image1);

image2.save("somefile.jpg", "JPG");

I'd try some...

简短的回答: 在你的QImage构造函数中使用Format_RGB32而不是Format_Indexed8 。 详细答案: Format_Indexed8使用手动定义的颜色表,其中每个索引表示一种颜色。 你必须为你的图像创建自己的颜色表: QVector color_table;

for (int i = 0; i < 256; ++i) {

color_table.push_back(qRgb(i, i, i)); // Fill the color table with B...

相关文章

在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec

...

Windowsis an extremely effective and a an efficient

...

http://gumstix.org/create-a-bootable-microsd-card.h

...

Open [Tomcat install dir]\tomcat-users.xmlfor editi

...

经常在维基百科等网站看到目录列表,点击链接会跳到具体的位置,小美眉一直在问是怎么做到的,其实挺简单

...

http://spark-project.org/ 项目首页 http://shark.cs.berk

...

这篇文件写的非常好,推荐大家重温一下: http://highscalability.com/blog

...

查看jQuery EasyUI的帮助说明,getSelected是获取选中行的数据,但当我没有选中当前

...

pro-du-cer n. 1. Someone from a game publisher who

...

Data Week: Becoming a data scientist Data Pointed,

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定


版权声明:本文为weixin_35498756原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。