用Qlabel Qt JPG图像显示

时间:2012-08-13 00:08:11

标签: linux qt jpeg

我是QT新手。我正在尝试开发一个简单的应用程序来显示Mobotix相机的图像。相机通过http以jpeg图像的形式提供视频输入。作为测试,我在Qt 4.8上在Ubuntu 12.04 32位x86上开发了一个小应用程序。无论如何我都无法显示jpg图像。如何显示没有问题的GIF。相机只能以jpg格式提供图像。下面的程序编译正常,但没有显示任何内容。以下行在“从不支持的顺序设备读取ras文件”中显示两次。我甚至试图明确指定图像格式,但仍然没有显示图像。我已经尝试了QImage和QImageReader,但无济于事。作为一个实验,我试图编译示例共享内存应用程序。这也适用于png图像,但它也根本无法显示任何jpg图像。我的imageformats文件夹有libqjpeg.so

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QLabel>
#include <QtNetwork>
#include <QUrl>
#include <QImageReader>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT
public slots:
    void ImageLoad();

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private slots:
    void on_pushButton_clicked();

private:
    Ui::Dialog *ui;
    QImage Camera_Image;
    QUrl url;
    QNetworkAccessManager manager;
    QNetworkRequest request;
    QNetworkReply *reply;
};

#endif // DIALOG_H

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}

//void Dialog::ImageLoad()
//{
//    Camera_Image.load(reply,"GIF");
////    CameraImageReader.setAutoDetectImageFormat(false);
////    CameraImageReader.setFormat("JPEG");
//    ui->label->setPixmap(QPixmap::fromImage(Camera_Image));
//}

//void Dialog::on_pushButton_clicked()
//{
//    url.setUrl("http://images.my-addr.com/img/exam_gif_to_png.gif");
//    request.setUrl(url);
//    reply = manager.get(request);
//    QObject::connect( reply, SIGNAL(finished()), this, SLOT(ImageLoad()));
//}

void Dialog::ImageLoad()
{
    QImageReader CameraImageReader(reply,reply->readAll());
//    CameraImageReader.setAutoDetectImageFormat(false);
//    CameraImageReader.setFormat("JPEG");
    ui->label->setPixmap(QPixmap::fromImageReader(&CameraImageReader));
}

void Dialog::on_pushButton_clicked()
{
    url.setUrl("https://community.emc.com/servlet/JiveServlet/downloadImage/38-5115-42202/600-600/cygnus.jpg");
    request.setUrl(url);
    reply = manager.get(request);
    QObject::connect( reply, SIGNAL(finished()), this, SLOT(ImageLoad()));
}

0 个答案:

没有答案
相关问题