Last active
September 10, 2015 08:48
-
-
Save pauljurczak/2b6ba7987e80987591e5 to your computer and use it in GitHub Desktop.
Fractional pixel size with Qt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include <QGraphicsScene> | |
#include <QLabel> | |
#include <QBrush> | |
#include <QGraphicsSimpleTextItem> | |
#include <QColor> | |
#include <QGraphicsView> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
const int scale = 44; | |
QApplication a(argc, argv); | |
QGraphicsScene scene; | |
QGraphicsView view(&scene); | |
QImage image("test.bmp"); | |
scene.addPixmap(QPixmap::fromImage(image.scaled(image.width(), image.height()))); | |
for (int x = 0; x < image.width(); ++x) | |
for (int y = 0; y < image.height(); ++y) { | |
auto text = new QGraphicsSimpleTextItem(); | |
text->setText(QString::number(qGray(image.pixel(x, y)))); | |
text->setBrush(QBrush(Qt::red)); | |
text->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); | |
text->setPos(view.mapFromScene(x+0.2, y+0.2)); | |
scene.addItem(text); | |
} | |
view.scale(scale, scale); | |
view.show(); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment