当前位置: 首页 > news >正文

通过php获取手机网站访客的手机号码seo网站建设优化什么意思

通过php获取手机网站访客的手机号码,seo网站建设优化什么意思,购物网站含有哪些模块,淘客推广代理背景 软件的一个功能是: 打开图片在图片上绘制序号,序号的样式是圆圈内包含数字将带有序号的图片打印出来 实现思路也很简单,在屏幕上显示时重写paintEvent函数,利用QPainter完成图片和序号的绘制。打印时只需要将QPainter对应…

背景

软件的一个功能是:

  1. 打开图片
  2. 在图片上绘制序号,序号的样式是圆圈内包含数字
  3. 将带有序号的图片打印出来

实现思路也很简单,在屏幕上显示时重写paintEvent函数,利用QPainter完成图片和序号的绘制。打印时只需要将QPainter对应的QPaintDevice切换成QPrinter就可以了。

具体来说就是利用drawEllipse绘制圆圈,利用drawText绘制数字,利用QFontsetPointSizeF设置数字大小,以适配圆圈大小。

问题

这个功能的逻辑不算复杂,在开发时没有什么问题,能够正常显示和打印。
但是在测试阶段发现如下问题:

  1. 屏幕上显示的序号看上去很正常,但打印出的序号数字明显变小了
  2. 换了一台机器运行,序号中的数字变得很大,导致数字只能部分显示。

这两个问题都是字体相对于圆圈大小的问题。

原因

Qt提供了两种方法设置字体大小:

  • setPixelSize

    Sets the font size to pixelSize pixels, with a maxiumum size of an unsigned 16-bit integer.

    Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner.

  • setPointSize/setPointSizeF

    Sets the point size to pointSize. The point size must be greater than zero.

按照官方文档的说法,通过setPointSizeF设置字体大小,可以做到与设备无关。但上面遇到的问题明显是和QPainter对应的设备有关。
对于第一个问题,屏幕绘制与打印唯一的区别就是QPainterQPaintDevice不同,所以基本可以确定问题出在QPaintDevice上。
第二个问题基本可以确认是硬件上的原因,进一步推定是屏幕的原因。

一番测试后,基本确定是由于QPaintDevice的DPI不同造成的

尝试给出最小复现代码:

  1. 自定义QPaintDevice,实现不同DPI的QPaintDevice
  2. 利用QPainter在自定义QPaintDevice上绘制序号

对比不同DPI对绘制效果的影响。

const int customDPI = 48 * 2;
class CustomPaintDevice : public QPaintDevice {
public:CustomPaintDevice(int width, int height) : image(width, height, QImage::Format_ARGB32_Premultiplied) {image.fill(Qt::white);}QImage getImage() const { return image; }
protected:int metric(PaintDeviceMetric metric) const override {switch (metric) {case PdmWidth:return image.width();case PdmHeight:return image.height();case PdmDpiX:case PdmDpiY:return customDPI;default:return 0;}}QPaintEngine* paintEngine() const override {return image.paintEngine();}
private:QImage image;
};
class TestDeviceDPI : public QWidget
{Q_OBJECT
public:explicit TestDeviceDPI(QWidget *parent = nullptr) : QWidget{parent} {}
protected:void paintEvent(QPaintEvent *e) {int diameter = 50; // diameter of circleQPoint pos(100,100);QPainter customDevicePainter;CustomPaintDevice *customDevice = new CustomPaintDevice(500,500); // Define dimensionscustomDevicePainter.begin(customDevice);QFont font;font.setPointSizeF(diameter / 2.0);font.setBold(true);customDevicePainter.setFont(font);customDevicePainter.drawText(QRectF(pos.x() - diameter / 2.0, pos.y() - diameter / 2.0, diameter, diameter),Qt::AlignmentFlag::AlignCenter, QString::number(10));customDevicePainter.drawEllipse(QRectF(pos.x() - diameter / 2.0,pos.y() - diameter / 2.0,diameter, diameter));customDevicePainter.end();QPainter widgetPainter(this);QImage renderedImage = customDevice->getImage();widgetPainter.drawImage(0, 0, renderedImage);QWidget::paintEvent(e);}
};

在保持diameter不变的情况下,分别设置customDPI为48、96、192效果如下图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

规律非常明显,DPI越大,绘制字体的效果越大,但圆圈大小保持不变

不知道是不是哪里使用出了问题,至少目前看来QPaintDevice的DPI会影响drawText的字体大小,但不会影响drawEllipse

解决

方案1

尝试使用setPixelSize设置字体大小,发现不会出现上面说的问题,这和官方文档的说法正好相反,我都有些怀疑是不是我英语不好理解错了……
但官方文档在setPixelSize下的说法:

Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner.

分明就是setPixelSize与设备相关,setPointSize与设备无关……

方案2

另一个方案就是在设置字体大小时将DPI这个因素考虑进去即可

customDevicePainter.begin(customDevice);QFont font;float baseDpi = 96; // Typical DPI for a QWidgetfloat deviceDpi = p->device()->logicalDpiY();font.setPointSizeF((diameter / 2.0) / (deviceDpi / baseDpi));font.setBold(true);customDevicePainter.setFont(font);customDevicePainter.drawText(QRectF(pos.x() - diameter / 2.0, pos.y() - diameter / 2.0, diameter, diameter),Qt::AlignmentFlag::AlignCenter, QString::number(10));customDevicePainter.drawEllipse(QRectF(pos.x() - diameter / 2.0,pos.y() - diameter / 2.0,diameter, diameter));customDevicePainter.end();

虽然找到了解决方案,但没能完全明白问题所在。
各位大神有清楚的请多指教。

http://www.yidumall.com/news/101333.html

相关文章:

  • 百度站长收录某网站seo策划方案
  • 网站收录了怎么做排名拓客平台有哪些
  • 公司网站开发费用怎么做账百度推广账户登录首页
  • 网站设计一般会遇到哪些问题网络销售网站
  • sns有哪些著名的网站有哪些30个免费货源网站
  • ps网站轮播图怎么做百度搜索关键词热度
  • 外网购物平台太原seo推广外包
  • 做网站排名收益seo与sem的区别和联系
  • 青岛网站建设定制开发东莞seo建站如何推广
  • 沈阳哪家做网站最好什么是seo和sem
  • 深圳市建网站公万能推广app
  • 河南建设工程造价管理协会网站公众号怎么开通
  • 最好用的网站推广经验营销型网站建设的重要原则
  • 安徽网站建设大全百度快速优化软件排名
  • 做医疗器械网站域名访问网站入口
  • 晚上做羞羞的事情视频网站免费的郑州网络推广服务
  • 建设一个网站思路网店产品seo如何优化
  • 用模板做的网站不好优化找广告商的平台
  • 网站建站公司服务好吗seo推广有哪些公司
  • 网站的结构小广告图片
  • 山西大同网站建设价格seo推广效果怎么样
  • 宁波专业平台网站建设aso优化软件
  • 电商网站图片处理常见网络营销推广方法
  • pc端网站建设联系方式优化网站标题是什么意思
  • 设计类专业排名石家庄seo公司
  • 网页设计的网站网络广告推广服务
  • 做网站如何挣钱十大网络舆情案例
  • 服务器做视频网站长沙seo排名优化公司
  • 找哪些公司做网站产品线上营销有哪些方式
  • wordpress企业网站seo百度导航最新版本免费下载