You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.2 KiB
C

#ifndef BITMAP_H
#define BITMAP_H
//Qt
#include <QColor>
#include <QPainter>
#include <QPainterPath>
#include <QPaintEvent>
#include <QVector>
#include <QPainterPathStroker>
#include <QPen>
#include <QWidget>
#include <QPaintEngine>
#include <QPoint>
#include <QBitmap>
#include <QPixmap>
#include <QDebug>
#include <QIODevice>
#include <QDir>
#include <QCursor>
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