获取网页高宽属性

<script language="javascript">
function screenInfo(){
    var  s = "";
   s += "/r/n网页可见区域宽:"+ document.body.clientWidth;
   s += "/r/n网页可见区域高:"+ document.body.clientHeight;
   s += "/r/n网页可见区域宽:"+ document.body.offsetWidth  +" (包括边线的宽)";
   s += "/r/n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
   s += "/r/n网页正文全文宽:"+ document.body.scrollWidth;
   s += "/r/n网页正文全文高:"+ document.body.scrollHeight;
   s += "/r/n网页被卷去的高:"+ document.body.scrollTop;
   s += "/r/n网页被卷去的左:"+ document.body.scrollLeft;
   s += "/r/n网页正文部分上:"+ window.screenTop;
   s += "/r/n网页正文部分左:"+ window.screenLeft;
   s += "/r/n屏幕分辨率的高:"+ window.screen.height;
   s += "/r/n屏幕分辨率的宽:"+ window.screen.width;
   s += "/r/n屏幕可用工作区高度:"+ window.screen.availHeight;
   s += "/r/n屏幕可用工作区宽度:"+ window.screen.availWidth;
   alert(s);
}
</script> 
### 使用 Qt 获取 QImage 和 QPixmap 的度和宽度 在 Qt 中,`QImage` 和 `QPixmap` 是两种常用的图像处理类。它们提供了多种方法来操作和查询图像属性。 #### 对于 QImage 可以通过调用成员函数 `.width()` 和 `.height()` 来分别获取图像的宽度和度[^1]: ```python qimage = QImage("path/to/image.png") # 加载一张图片 if not qimage.isNull(): # 检查图片是否成功加载 width = qimage.width() # 获取宽度 height = qimage.height() # 获取度 print(f"Width: {width}, Height: {height}") else: print("Failed to load image.") ``` 如果需要调整图像的度并保持宽比例不变,则可以使用 `scaledToHeight` 函数: ```python new_height = 200 resized_image = qimage.scaledToHeight(new_height) print(f"Resized Width: {resized_image.width()}, Resized Height: {resized_image.height()}") ``` #### 对于 QPixmap 同样地,对于 `QPixmap` 类型的对象,也可以通过 `.width()` 和 `.height()` 成员函数获取其尺寸信息[^2]: ```python qpixmap = QPixmap("path/to/image.png") # 加载一张图片 if not qpixmap.isNull(): # 检查图片是否成功加载 width = qpixmap.width() # 获取宽度 height = qpixmap.height() # 获取度 print(f"Width: {width}, Height: {height}") else: print("Failed to load pixmap.") ``` 需要注意的是,在某些情况下可能需要先将 `QPixmap` 转换为 `QImage` 才能进一步访问像素级的数据。例如: ```python qimage = qpixmap.toImage() buf = qimage.constBits().asarray(qimage.byteCount()) np_array = np.frombuffer(buf, dtype=np.uint8).reshape((qimage.height(), qimage.width(), 4)) ``` 上述代码片段展示了如何将 `QPixmap` 转换为 NumPy 数组以便后续处理。 另外,当尝试从文件路径创建一个 `QImage` 实例时,应验证对象的状态以确认加载过程无误[^4]: ```cpp QString filePath = qApp->applicationDirPath() + "/test.png"; QImage image(filePath); if (image.isNull()) { qDebug() << "Error loading image."; } else { qDebug() << "Image loaded successfully:" << image.width() << "x" << image.height(); } ``` 以上方法适用于大多数场景下的图像尺寸查询需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值