「QPicture」の編集履歴(バックアップ)一覧はこちら
「QPicture」(2014/08/12 (火) 22:36:17) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
**QPictureクラスとは
QPicture クラスは描写を行う QPainter クラスの命令を記録し、再現するための描写デバイスを提供します。
QPicture クラスはプラットフォームに依存しない形式でIOデバイスに対する「描画命令」をシリアライズします。
こうしたものは「[[メタファイル>http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%BF%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB]]」とも呼ばれます。
QPicture オブジェクトを表現する画像形式(以下Qt画像と呼ぶ)は独自のバイナリフォーマットを使用します。
QPicture オブジェクトは異なるデバイス間でも同じ見た目で表現できるように内部で自動調整されます。
**メソッド
***コンストラクタ
|QPicture::QPicture(int formatVersion = -1)|
空の QPicture オブジェクトを生成します。
フォーマットバージョン formatVersion は以前のバージョンのQtでコンパイルされたアプリケーションで読み込める QPicture オブジェクトを生成するために使用できます。
デフォルト引数の formatVersion は -1 で現在のリリースバージョンを表します。
***コピーコンストラクタ
|QPicture::QPicture(const QPicture & pic)|
([[Implicit Sharing]])です。
***デストラクタ
|QPicture::~QPicture()|
***画像を囲む長方形を取得・設定
|QRect QPicture::boundingRect() const|
本オブジェクトが表す画像を囲む長方形を返します。
空の QPicture オブジェクトの場合は、無効の長方形( QRect::isValid() の返り値がfalse )を返します。
|void QPicture::setBoundingRect(const QRect & r)|
本オブジェクトが表す画像を囲む長方形を設定します。
既に設定されている値は上書きされます。
***データ及びサイズを取得・設定
|const char * QPicture::data() const|
本オブジェクトが表す画像のバイト配列の先頭アドレスのポインタを返します。
バイト配列なので QByteArray クラスなどで取り扱うこともできます。
このポインタは本オブジェクトに対する非const関数が呼ばれるまで有効です。
空の QPicture オブジェクトの場合は、バイト配列はヌル文字を表します。
const char* data = picture.data()
//空の QPicture オブジェクトの場合、*dataはヌル文字("\0")
//有効な QPicture オブジェクトの場合、*dataはQt画像を表すバイト配列
|uint QPicture::size() const|
本オブジェクトが表す画像のサイズを返します。
|void QPicture::setData(const char * data, uint size) [virtual]|
Qt画像を表すバイト配列 data とファイルサイズ size を指定して、本オブジェクトが表す画像を設定します。
***読み込み・保存
|bool QPicture::load(const QString & fileName, const char * format = 0)|
ファイルパス fileName で指定したファイル(Qt画像形式)から読み込み、本オブジェクトが表す画像を設定します。
成功した場合はtrue、そうでない場合はfalseを返します。
format 引数は廃止されました
|bool QPicture::load(QIODevice * dev, const char * format = 0)|
デバイス dev からQt画像を読み込みます。
|bool QPicture::save(const QString & fileName, const char * format = 0)|
ファイルパス fileName に QPicture オブジェクトの内容をQt画像形式として保存します。
成功した場合はtrue、そうでない場合はfalseを返します。
|bool QPicture::save(QIODevice * dev, const char * format = 0)|
デバイス dev に QPicture オブジェクトの内容をQt画像形式として保存します。
***再生
|bool QPicture::play(QPainter * painter)|
QPainter オブジェクト painter を使用して画像を描写します。
成功した場合はtrue、そうでない場合はfalseを返します。
***空のオブジェクトかどうか
|bool QPicture::isNull() const|
空の QPicture オブジェクトの場合はtrue、そうでない場合falseを返します。
***入れ替え
|void QPicture::swap(QPicture & other)|
入れ替えたい QPicture オブジェクト other と本オブジェクトの内容を交換します。
****サンプルコード
#highlight(){
QPicture pictureA;
QPicture pictureB;
//pictureA に楕円を描写
QPainter painter(&pictureA);
painter.drawEllipse(30,30, 100,100);
painter.end();
//本オブジェクトが表す画像をBase64エンコードして可視化
qDebug() << "pictureA: " << QByteArray(pictureA.data()).toBase64();
qDebug() << "pictureB: " << QByteArray(pictureB.data()).toBase64();
pictureA.swap(pictureB);
qDebug() << "pictureA: " << QByteArray(pictureA.data()).toBase64();
qDebug() << "pictureB: " << QByteArray(pictureB.data()).toBase64();
}
****結果
#highlight(){
pictureA: "UVBJQzvv"
pictureB: ""
pictureA: ""
pictureB: "UVBJQzvv"
}
***演算子オーバーロード
|QPicture & QPicture::operator=(const QPicture & p)|
QPicture オブジェクト p を本オブジェクトの内容に設定します。
|QPicture & QPicture::operator=(QPicture && other)|
**QPictureクラスとは
QPicture クラスは描写を行う QPainter クラスの命令を記録し、再現するための描写デバイスを提供します。
QPicture クラスはプラットフォームに依存しない形式でIOデバイスに対する「描画命令」をシリアライズします。
こうしたものは「[[メタファイル>http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%BF%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB]]」とも呼ばれます。
QPicture オブジェクトを表現する画像形式(以下Qt画像と呼ぶ)は独自のバイナリフォーマットを使用します。
QPicture オブジェクトは異なるデバイス間でも同じ見た目で表現できるように内部で自動調整されます。
**メソッド
***コンストラクタ
|QPicture::QPicture(int formatVersion = -1)|
空の QPicture オブジェクトを生成します。
フォーマットバージョン formatVersion は以前のバージョンのQtでコンパイルされたアプリケーションで読み込める QPicture オブジェクトを生成するために使用できます。
デフォルト引数の formatVersion は -1 で現在のリリースバージョンを表します。
***コピーコンストラクタ
|QPicture::QPicture(const QPicture & pic)|
([[Implicit Sharing]])です。
***デストラクタ
|QPicture::~QPicture()|
***画像を囲む長方形を取得・設定
|QRect QPicture::boundingRect() const|
本オブジェクトが表す画像を囲む長方形を返します。
空の QPicture オブジェクトの場合は、無効の長方形( QRect::isValid() の返り値がfalse )を返します。
|void QPicture::setBoundingRect(const QRect & r)|
本オブジェクトが表す画像を囲む長方形を設定します。
既に設定されている値は上書きされます。
****サンプルコード
#highlight(){
QPicture pictureA;
QPicture pictureB;
//pictureA に楕円を描写
QPainter painter(&pictureA);
painter.drawEllipse(30,30, 100,100);
painter.end();
QRect rectA = pictureA.boundingRect();
qDebug() << "pictureA: (" << rectA.topLeft().x() << ", " << rectA.topLeft().y() << ")" << rectA.width() << " * " << rectA.height();
QRect rectB = pictureB.boundingRect();
qDebug() << "pictureB: " << rectB.isValid();
}
****結果
#highlight(){
pictureA: ( 30 , 30 ) 100 * 100
pictureB: false
}
***データ及びサイズを取得・設定
|const char * QPicture::data() const|
本オブジェクトが表す画像のバイト配列の先頭アドレスのポインタを返します。
バイト配列なので QByteArray クラスなどで取り扱うこともできます。
このポインタは本オブジェクトに対する非const関数が呼ばれるまで有効です。
空の QPicture オブジェクトの場合は、バイト配列はヌル文字を表します。
const char* data = picture.data()
//空の QPicture オブジェクトの場合、*dataはヌル文字("\0")
//有効な QPicture オブジェクトの場合、*dataはQt画像を表すバイト配列
|uint QPicture::size() const|
本オブジェクトが表す画像のサイズを返します。
****サンプルコード
#highlight(){
QPicture pictureA;
QPicture pictureB;
//pictureA に楕円を描写
QPainter painter(&pictureA);
painter.drawEllipse(30,30, 100,100);
painter.end();
qDebug() << "pictureA: data:" << pictureA.data() << "size: " << pictureA.size();
qDebug() << "pictureB: data:" << pictureB.data() << "size: " << pictureA.size(); //data()が返すポインタの参照先はヌル文字
}
****結果
#highlight(){
pictureA: data: QPIC;? size: 68
pictureB: data: size: 68
}
|void QPicture::setData(const char * data, uint size) [virtual]|
Qt画像を表すバイト配列 data とファイルサイズ size を指定して、本オブジェクトが表す画像を設定します。
***読み込み・保存
|bool QPicture::load(const QString & fileName, const char * format = 0)|
ファイルパス fileName で指定したファイル(Qt画像形式)から読み込み、本オブジェクトが表す画像を設定します。
成功した場合はtrue、そうでない場合はfalseを返します。
format 引数は廃止されました
|bool QPicture::load(QIODevice * dev, const char * format = 0)|
デバイス dev からQt画像を読み込みます。
|bool QPicture::save(const QString & fileName, const char * format = 0)|
ファイルパス fileName に QPicture オブジェクトの内容をQt画像形式として保存します。
成功した場合はtrue、そうでない場合はfalseを返します。
|bool QPicture::save(QIODevice * dev, const char * format = 0)|
デバイス dev に QPicture オブジェクトの内容をQt画像形式として保存します。
****サンプルコード
#highlight(){
QPicture picture;
QPainter painter(&picture);
painter.drawEllipse(30,30, 100,100);
painter.end();
picture.save("Qt.pic");
}
***再生
|bool QPicture::play(QPainter * painter)|
QPainter オブジェクト painter を使用して画像を描写します。
成功した場合はtrue、そうでない場合はfalseを返します。
****サンプルコード
#highlight(){
QPainter painter(this);
QPicture picture;
picture.load("Qt.pic"); //Qt画像ファイル「Qt.pic」をカレントディレクトリからロード
picture.play(&painter); //指定したQPainterオブジェクトで描写
}
***空のオブジェクトかどうか
|bool QPicture::isNull() const|
空の QPicture オブジェクトの場合はtrue、そうでない場合falseを返します。
****サンプルコード
#highlight(){
QPicture pictureA;
QPicture pictureB;
//pictureA に楕円を描写
QPainter painter(&pictureA);
painter.drawEllipse(30,30, 100,100);
painter.end();
qDebug() << "pictureA: " << pictureA.isNull();
qDebug() << "pictureB: " << pictureB.isNull();
}
****結果
#highlight(){
pictureA: false
pictureB: true
}
***入れ替え
|void QPicture::swap(QPicture & other)|
入れ替えたい QPicture オブジェクト other と本オブジェクトの内容を交換します。
****サンプルコード
#highlight(){
QPicture pictureA;
QPicture pictureB;
//pictureA に楕円を描写
QPainter painter(&pictureA);
painter.drawEllipse(30,30, 100,100);
painter.end();
//本オブジェクトが表す画像をBase64エンコードして可視化
qDebug() << "pictureA: " << QByteArray(pictureA.data()).toBase64();
qDebug() << "pictureB: " << QByteArray(pictureB.data()).toBase64();
pictureA.swap(pictureB);
qDebug() << "pictureA: " << QByteArray(pictureA.data()).toBase64();
qDebug() << "pictureB: " << QByteArray(pictureB.data()).toBase64();
}
****結果
#highlight(){
pictureA: "UVBJQzvv"
pictureB: ""
pictureA: ""
pictureB: "UVBJQzvv"
}
***演算子オーバーロード
|QPicture & QPicture::operator=(const QPicture & p)|
QPicture オブジェクト p を本オブジェクトの内容に設定します。
|QPicture & QPicture::operator=(QPicture && other)|