我不明白QImage和QPixmap有什么区别,它们似乎提供相同的功能.我什么时候应该使用QImage?何时应该使用QPixmap?
我无法读取和写入QByteArray数据到文件.
我的目标是将QPixmap数据保存到QByteArray中,并将QByteArray保存到文件中(能够从文件读回QByteArray并进入QPixmap).我想使用QPixmap文档中的以下代码:
QPixmap pixmap(<image path>);
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
Run Code Online (Sandbox Code Playgroud)
在将缓冲区写入文件后,我希望能够使用QPixmap :: loadFromData()函数检索QByteArray并将其加载回QPixmap.
如果需要进一步澄清,请告诉我(我也对其他方法持开放态度,我只需要能够将QPixmap读写到文件中!:));
我是Qt/Embedded的新手.我想用它QPainter来绘制一个东西QPixmap,它将被添加到QGraphicsScene.这是我的代码.但它没有在像素图上显示图纸.它只显示黑色像素图.
int main(int argc, char **argv) {
QApplication a(argc, argv);
QMainWindow *win1 = new QMainWindow();
win1->resize(500,500);
win1->show();
QGraphicsScene *scene = new QGraphicsScene(win1);
QGraphicsView view(scene, win1);
view.show();
view.resize(500,500);
QPixmap *pix = new QPixmap(500,500);
scene->addPixmap(*pix);
QPainter *paint = new QPainter(pix);
paint->setPen(*(new QColor(255,34,255,255)));
paint->drawRect(15,15,100,100);
return a.exec();
}
Run Code Online (Sandbox Code Playgroud) 是否记录了任何已知的尺寸/空间限制QPixmap和/或QImage对象?我没有找到任何有用的信息.我目前在OSX和Windows上使用Qt 4.7.3.特别是我对以下内容感兴趣:
我天真地怀疑记忆是唯一的限制因此,人们可以通过计算最大尺寸
width x height x byte_per_pixel
我认为有一个更精细的经验法则; 当你遇到GB尺寸时,32位机器也可能有解决问题.
最后,我希望存储大小约为16000x16000像素的多个RGBA图像,并在a中使用透明度将它们渲染到彼此QGraphicsScene.可用的工作站可以有很多RAM,比方说16GB.
tl; dr:您了解QImage/QPixmap的大小限制,或者我在哪里可以找到此类信息?
编辑:我知道平铺方法,我很好.知道上述事情仍然会很棒.
谢谢!
既然不推荐使用QPixmap :: toWinHBITMAP(),我找不到从QPixmap(或QImage)获取HBITMAP的方法.
谷歌搜索,我发现有一个名为qt_pixmapToWinHBITMAP()的函数似乎可以做我需要的,但我找不到我应该启用的模块-if any-在我的.pro文件中或者我应该包含哪些标题来使用它,或者也许别的东西.
我需要HBITMAP的原因是使用VFW创建视频.当然,我很乐意只使用Qt来做到这一点.有QtMultimedia模块,但据我所知,它不会导出视频,所以我想我一直坚持使用windows api.
任何帮助,将不胜感激.
我在Qt Creator的作业中工作,在那里我画到QWidget,我需要保存这个QWdiget的一部分.
我试图解决这个问题:
QPixmap pixmap;
pixmap.copy(rectangle); // rectangle is part of QWidget, which I need to save
pixmap.save("example.png");
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我以前习惯QVideoProbe使用相机镜架.我的平台是Android.我已将每个相机帧转换为QImagepixmap并显示QLabel.我的问题是这个过程很慢.帧显示得非常慢.我可以QVideoFrame直接转换为QPixmap其他更快的方式来显示相机帧吗?这是我的代码:
QCamera *camera = new QCamera(this);
camera->setCaptureMode(QCamera::CaptureViewfinder);
QVideoProbe *videoProbe = new QVideoProbe(this);
bool ret = videoProbe->setSource(camera);
qDebug() <<"videoProbe->setSource(camera):" << ret;
if (ret) {
connect(videoProbe, SIGNAL(videoFrameProbed(const QVideoFrame &)),
this, SLOT(present(const QVideoFrame &)));
}
camera->start();
...
...
bool MainWindow::present(const QVideoFrame &frame)
{
qDebug() <<"counter:" << ++counter;
QVideoFrame cloneFrame(frame);
if(cloneFrame.map(QAbstractVideoBuffer::ReadOnly))
{
QImage img(
cloneFrame.size(), QImage::Format_ARGB32);
qt_convert_NV21_to_ARGB32(cloneFrame.bits(),
(quint32 *)img.bits(),
cloneFrame.width(),
cloneFrame.height());
label->setPixmap(QPixmap::fromImage(img));
cloneFrame.unmap();
}
return true;
}
Run Code Online (Sandbox Code Playgroud) 尝试链接PyQt和Opencv视频源,无法理解如何应用while循环连续流式传输视频.它只需要一张照片.请任何人都可以帮助解决问题.
PtQt = 5
蟒蛇= 3.6.1
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 Video'
self.left = 100
self.top = 100
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.resize(1800, 1200)
#create a label
label = QLabel(self)
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
convertToQtFormat = QtGui.QImage(rgbImage.data, rgbImage.shape[1], rgbImage.shape[0],
QtGui.QImage.Format_RGB888)
convertToQtFormat = QtGui.QPixmap.fromImage(convertToQtFormat)
pixmap = QPixmap(convertToQtFormat)
resizeImage = pixmap.scaled(640, 480, QtCore.Qt.KeepAspectRatio)
QApplication.processEvents()
label.setPixmap(resizeImage)
self.show()
if __name__ == '__main__':
app = …Run Code Online (Sandbox Code Playgroud) 我想在QLabel小部件中显示图像.图像位于./images/相对于resource.qrc文件的文件夹中,并包含如下:
<RCC>
<qresource prefix="/images">
<file>image.png</file>
</qresource>
</RCC>
Run Code Online (Sandbox Code Playgroud)
现在我想在以下内容中显示图像QLabel:
QPixmap pixmap( ":/images/image.png" );
label->setPixmap( pixmap );
Run Code Online (Sandbox Code Playgroud)
这不起作用.在调试模式下pixmap = NULL.我认为qrc路径是错误的.使用图像的绝对系统路径,c:/images/...它可以正常工作.任何的想法?
任何人都可以帮我在qt中调整图像大小而不会使图像像素化.这是我的代码.结果不如原始质量好.谢谢......
QImage img(name);
QPixmap pixmap;
pixmap = pixmap.fromImage(img.scaled(width,height,Qt::IgnoreAspectRatio,Qt::FastTransformation));
QFile file(folder+"/"+name);
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "jpeg",100);
file.close();
Run Code Online (Sandbox Code Playgroud)