레이블이 이미지 출력인 게시물을 표시합니다. 모든 게시물 표시
레이블이 이미지 출력인 게시물을 표시합니다. 모든 게시물 표시

2014년 1월 14일 화요일

Qt 이미지 출력


Qt에서 이미지 출력하는 방법

보통 QLabel에 출력하는 방법을 많이 사용한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
#include <QPixmap>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
 
    QString img_path = "C:/AMD/SDC11388.JPG";
    QImage img(img_path);    
    QPixmap buf = QPixmap::fromImage(img);
 
    ui->label->setPixmap(buf);
    ui->label->resize(buf.width(), buf.height());
}
 
MainWindow::~MainWindow()
{
    delete ui;
}
 



QGraphicsView에 출력하는 방법도 사용한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
#include <QPixmap>
#include <QGraphicsView>
#include <QGraphicsScene>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
 
    QString img_path = "C:/AMD/SDC11388.JPG";
    QImage img(img_path);    
    QPixmap buf = QPixmap::fromImage(img);
    
    buf = buf.scaled(1024,1024);
 
 
    QGraphicsScene* scene = new QGraphicsScene;
    ui->graphicsView->setScene(scene);
 
    scene->addPixmap(buf);
 
}
 
MainWindow::~MainWindow()
{
    delete ui;
}