

如何在OpenHarmony应用侧获取屏幕DPI
source link: https://www.51cto.com/article/768978.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何在OpenHarmony应用侧获取屏幕DPI

1、应用侧获取屏幕DPI 实现思路
如图这是笔者的两台OpenHarmony设备,左边汇思博SEEK100 sl8541e的DPI为213,右边润开鸿 DAYU200的DPI为240。

通过导入@ohos.display包来使用getDefaultDisplaySync()方法以获取屏幕 DPI值的方法。
import display from '@ohos.display';
@Entry
@Component
struct Index {
@State displayClass: display.Display | null = null
aboutToAppear(){
try {
this.displayClass = display.getDefaultDisplaySync();
console.info('Test densityDPI:' + JSON.stringify(this.displayClass.densityDPI));
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
}
build() {
Row() {
Column() {
Text('屏幕DPI是'+JSON.stringify(this.displayClass.densityDPI))
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
2、更改开发板的屏幕DPI(以DAYU200为例)
(1)方法一:更改源码编译烧录固件
在源码foundation/window/window_manager/resources/config/rk3568/display_manager_config.xml文件中修改dpi,编译后烧录固件。
<!--Window display dpi, valid range is 80~640, use 0 if no configuration is requeired-->
<dpi>240</dpi>
(2)方法二:发送display_manager_config.xml文件至设备etc/window/resources
OpenHarmony固件编译烧录进入设备后,display_manager_config.xml文件会被预编译打包至设备端etc/window/resources目录下,什么,为什么只有window/resources字段,因为ohos_prebuilt_etc就是把文件放进设备的etc文件夹。
foundation/window/window_manager/resources/config/BULID.gn文件如下,
下面代码的意思是源码foundation/window/window_manager/resources/config/rk3568/display_manager_config.xml会真正安装在设备中的etc/window/resources文件位置,
ohos_prebuilt_etc("display_manager_config") {
if (device_name == "rk3568") {
source = "//foundation/window/window_manager/resources/config/rk3568/display_manager_config.xml"
install_enable = true
···
···
relative_install_dir = "window/resources"
}
步骤如下:
# 进入sdk\版本号\toolchain输入cmd打开命令行,重新加载系统为可读写
hdc_std shell mount -o remount,rw /
# 替换/etc/window/resources中的display_manager_config.xml文件
hdc_std file send C:\Users\jjh\display_manager_config.xml /etc/window/resources
# 然后重启开发板让设置生效
hdc reboot
3、参考资料
- https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-display.md。
- https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/faqs-graphics.md。
Recommend
-
50
GP和LP,谁才是DPI产生的第一责任人?
-
10
Mixed DPI and the X Window Systemwok/ tecnologia/ Mixed DPI and the X Window System I'm writing this article because I'm getting ti...
-
15
Windows 下的高 DPI 应用开发(UWP / WPF / Windows Forms / Win32) 发布于 2018-10-18 10:06 更新于 2021-01-04 12:33 ...
-
9
评估GP,只看IRR和DPI远远不够溯元育新41分钟前选取好的PME,才是LP功力的体现。#1 评估基金业绩,通常有4种指标
-
11
基于传统技术开发的 Windows 桌面应用,在高分辨率的显示设备上表现得“惨不忍睹”。随着高分辨率显示设备的普及,所有桌面应用程序的开发人员,都需要关注自己的软件在不同的 DPI 上的表现。 1 应用程序感知 DPI 变化
-
4
速览 DeFi 指数 DPI 的发展、成功和不足 金色财经 原创 2021-10-25 09:46 热度 265507 分享 微信扫一扫:分享 ...
-
7
4年DPI过1—揭秘澳银资本天使投资 澳银资本已形成了独具特色的天使投、管体系。 12月7日,深圳天使母基金发布了年度榜单,澳银资本管理的基金深圳澳银天使创业投资企业(有限合伙)再获表彰。 深圳天使母基金是全国规模最大的天...
-
6
想了解更多内容,请访问:
-
7
OpenHarmony应用编译 - 如何在源码中编译复杂应用(4.0-Release) 作者:TiZizzz 2023-12-11 17:30:52 在OpenHarmony系统中预安装应用的hap包会随系统编译打包到镜像中,目前有两种编译预安装应用hap包的方式,一...
-
7
OpenHarmony应用编译 - 如何在源码中编译复杂应用(3.2-Release) 作者:TiZizzz 2023-12-11 17:26:21 本文档以系统应用Launcher为例,带大家了解如何通过系统源码编译应用的方式来打包预安装应用。
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK