QCanvasImage Class
QCanvasImage はQCanvasPainter 用の画像クラスです。詳細...
| ヘッダー | #include <QCanvasImage> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter) |
| 以来: | Qt 6.11 |
| ステータス | テクニカルプレビュー |
パブリック関数
| QCanvasImage() | |
| QCanvasImage(const QCanvasImage &image) | |
| QCanvasImage(QCanvasImage &&other) | |
| ~QCanvasImage() | |
| int | height() const |
| int | id() const |
| bool | isNull() const |
| void | setTintColor(const QColor &color) |
| QSize | size() const |
| qsizetype | sizeInBytes() const |
| void | swap(QCanvasImage &other) |
| QColor | tintColor() const |
| int | width() const |
| operator QVariant() const | |
| QCanvasImage & | operator=(QCanvasImage &&other) |
| QCanvasImage & | operator=(const QCanvasImage &image) |
関連する非メンバー
| bool | operator!=(const QCanvasImage &lhs, const QCanvasImage &rhs) |
| bool | operator==(const QCanvasImage &lhs, const QCanvasImage &rhs) |
詳細説明
QCanvasImage はQCanvasPainter で使用される画像クラスです。画像を描画できるようにするには、QCanvasPainter::addImage() などで利用可能にする必要があります。その後、QCanvasPainter::drawImage() を使用して画像をそのままペイントしたり、QCanvasImagePattern ブラシを使用して塗りつぶしやストロークを行うことができます。
簡単な例を示します:
static QImage logoImage(":/qtlogo.png"); // Paint an image pattern. QCanvasImage bg = painter.addImage(logoImage, QCanvasPainter::ImageFlag::Repeat | QCanvasPainter::ImageFlag::GenerateMipmaps); QCanvasImagePattern ip(bg, 0, 0, 44, 32); painter.setFillStyle(ip); painter.fillRect(50, 50, 320, 230); // Paint a single image, with tint color. QCanvasImage logo = painter.addImage(logoImage); logo.setTintColor("#2cde85"); painter.drawImage(logo, 100, 80);

上記の例では、QImage は静的で、再描画のたびに addImage() が呼び出されます。画像とフラグが同じままであれば、addImage() はテクスチャとして再度アップロードする代わりにキャッシュから画像をフェッチするので、これは問題ではありません。しかし、より一般的な方法は、QCanvasImage 変数をクラス メンバとして持ち、QCanvasPainterItemRenderer::initializeResources() などでQCanvasPainter::addImage() を呼び出すことです。
QCanvasBrush およびQCanvasOffscreenCanvas と同様に、QCanvasImage は明示的に共有されます。詳細は、「暗黙的データ共有」およびQSharedDataPointer を参照してください。
注意: QCanvasImage オブジェクトには、テクスチャなどのグラフィック リソースへのハンドルだけが含まれます。デタッチが発生した場合でも、実際のリソース、つまり基礎となるテクスチャとその中の画像データが実際にコピーまたは複製されることはありません。実際のグラフィックス リソース(たとえば、QRhiTexture )の実際の所有者は、addImage ()を介して QCanvasImage を引き渡したQCanvasPainter です。
QCanvasImage は常に、それを作成したQCanvasPainter に属します。手動で画像を削除するには、removeImage() を呼び出します。しかし、ほとんどの場合、これは必要ありません。なぜなら、ペインターは、ペインター自身を破棄する際に、自動的に画像を破棄するからです。
メンバ関数のドキュメント
QCanvasImage::QCanvasImage()
デフォルト画像を作成します。
QCanvasImage::QCanvasImage(const QCanvasImage &image)
与えられたimage のコピーである画像を構築する。
[constexpr noexcept] QCanvasImage::QCanvasImage(QCanvasImage &&other)
移動-other から新しい QCanvasImage を構築します。
[noexcept] QCanvasImage::~QCanvasImage()
画像を破壊する。
int QCanvasImage::height() const
この画像の高さを返します。
int QCanvasImage::id() const
この画像のテクスチャIDを返します。画像がまだ割り当てられていない場合、これは 0 を返します。
isNull()も参照してください 。
bool QCanvasImage::isNull() const
画像がまだ割り当てられていない場合は true を返す。詳細はQCanvasPainter::addImage() を参照。
void QCanvasImage::setTintColor(const QColor &color)
画像の色合いcolor を設定します。この色は画像の色と掛け合わされ、画像を着色します。これは例えばアイコンを強調したり、テーマによって画像を調整するために使用できます。
tintColor()も参照して ください。
QSize QCanvasImage::size() const
この画像のサイズ(幅と高さ)を返します。
qsizetype QCanvasImage::sizeInBytes() const
この画像のサイズをバイト単位で返す。
QCanvasPainter addImage() が返された後は、CPU 側の データのコピーは保持しない。ソースが の場合、そもそも CPU 側の画像データはありません。したがって、この関数の結果は、基礎となるテクスチャに使用される GPU メモリの近似値となります。QImage offscreen canvas
注意: この値は、画像フォーマットと寸法に基づく推定値にすぎません。Qt は、テクスチャのデータが GPU 側のメモリにどのように保存され、どのように配置されるかを知りません。
注意: この関数はミップマップやマルチサンプルデータを考慮しません。
[noexcept] void QCanvasImage::swap(QCanvasImage &other)
この画像をother と入れ替える。この操作は非常に速く、失敗することはない。
QColor QCanvasImage::tintColor() const
画像の色合いを返します。デフォルト値はQt::white です。
setTintColor()も参照 。
int QCanvasImage::width() const
画像の横幅を返します。
QCanvasImage::operator QVariant() const
画像をQVariant として返します。
[noexcept] QCanvasImage &QCanvasImage::operator=(QCanvasImage &&other)
Move-other をこのQCanvasImage インスタンスに割り当てる。
QCanvasImage &QCanvasImage::operator=(const QCanvasImage &image)
与えられたimage をこの画像に割り当て、この画像への参照を返します。
関連する非会員
[noexcept] bool operator!=(const QCanvasImage &lhs, const QCanvasImage &rhs)
画像ハンドルlhs がrhs と異なる場合はtrue を返し、そうでない場合はfalse を返す。
operator==()も参照 。
[noexcept] bool operator==(const QCanvasImage &lhs, const QCanvasImage &rhs)
画像ハンドルlhs がrhs と等しければtrue を返し、そうでなければfalse を返す。
注意: 等しいとは、2つの画像オブジェクトが同じグラフィックリソースを参照し、色合いが同じであることを意味します。内容(ピクセルデータ)は比較されません。
operator!=()も参照 。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.