#ifndef BITMAP_H #define BITMAP_H //Qt #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class Bitmap { public: Bitmap(const QPoint& topLeft,const QPoint& bottomRight,QString fileName=nullptr){ _topLeft = topLeft; _bottomRight = bottomRight; _scaley = 1; _scalex = 1; // TODO 需要加入文件检测判断文件是否存在 _pixmap = QPixmap(fileName); } Bitmap(){ _scaley = 1; _scalex = 1; _pixmap = QPixmap(); } void paint(QPixmap& w, QPaintEvent *event=nullptr){ QPainter painter; painter.begin(&w); QPoint center = QPoint((_topLeft.x()+_bottomRight.x())/2/_scalex,(_topLeft.y()+_bottomRight.y())/2/_scaley); QPixmap p; center -= QPoint(_pixmap.width()/2,_pixmap.height()/2); painter.scale(_scalex,_scaley); painter.drawPixmap(center,_pixmap); painter.end(); } QPoint topLeft() const { return _topLeft; } void setTopLeft(const QPoint &topLeft) { _topLeft = topLeft; } QPoint bottomRight() const { return _bottomRight; } void setBottomRight(const QPoint &bottomRight) { _bottomRight = bottomRight; } double scalex() const { return _scalex; } void setScalex(double scalex) { _scalex = scalex; } double scaley() const { return _scaley; } void setScaley(double scaley) { _scaley = scaley; } QPixmap getPixmap() const { return _pixmap; } void setPixmap(const QPixmap &value) { _pixmap = value; } void setPixmap(const QString& fileName) { _pixmap = QPixmap(fileName);; } private: QPixmap _pixmap; QPoint _topLeft; QPoint _bottomRight; QColor _scaleColor; // 缩放 double _scalex; double _scaley; }; #endif // BITMAP_H