Originally Posted by
cmessineo
Hello, How would one return Image bits to QML from C++?
I have this code in c++:
....
QImage image
= m_pixmap.
copy(sx, sy, sw, sh
).
toImage();
image
= image.
convertToFormat(QImage::Format_ARGB32);
QByteArray bytes
((char *) image.
bits(), image.
byteCount());
return ?????
QImage image = m_pixmap.copy(sx, sy, sw, sh).toImage();
image = image.convertToFormat(QImage::Format_ARGB32);
QByteArray bytes((char *) image.bits(), image.byteCount());
return ?????
To copy to clipboard, switch view to plain text mode
How would I package up the
QByteArray properly and return the data to QML in rgba format, so it can be manipulated on the QML side?
Thanks
class ImageManipulator
: public QObject {public:
void setImage
(const QImage &img
) { m_image
= img;
} QImage image
() const { return m_image;
}
Q_INVOKABLE
QColor pixel
(int x,
int y
) const { return QColor(m_image.
pixel(x, y
));
} Q_INVOKABLE
void setPixel
(int x,
int y,
QColor c
) { m_image.
setPixel(x, y, c
);
}private:
};
class ImageManipulator : public QObject {
public:
ImageManipulator(QObject *parent = 0) : QObject(parent) {}
void setImage(const QImage &img) { m_image = img; }
QImage image() const { return m_image; }
Q_INVOKABLE QColor pixel(int x, int y) const { return QColor(m_image.pixel(x, y)); }
Q_INVOKABLE void setPixel(int x, int y, QColor c) { m_image.setPixel(x, y, c); }
private:
QImage m_image;
};
To copy to clipboard, switch view to plain text mode
Bookmarks