android - 了解 MauiImage BaseSize

标签 android visual-studio-2022 maui

我需要一些帮助来理解 Visual Studio 中 MauiImageBaseSize 参数,以及导入可缩放到不同屏幕密度(可能还有一些屏幕密度)的图像所需的过程。有关移动设备上图像密度缩放的基础知识。

假设我有一个宽度为 380px、高度为 168px 的 PNG 图像,如下所示。

Example image

documentation说:

The base size of the image can be specified by setting the BaseSize attribute to values that are divisible by 8:

那么...我现在该怎么办? 380px 不能被 8 整除。我是否将宽度更改为 384 或 376,如 BaseSize="376,168"?生成的图像是否会被裁剪 4 个像素?或者这里正确的解决方案是什么?

The value of the BaseSize attribute represents the baseline density of the image, and is effectively the 1.0 scale factor for the image (the size you would typically use in your code to specify the image size) from which all other density sizes are derived. This value will be used to ensure that images are correctly resized to different display densities. If you don't specify a BaseSize for a bitmap image, the image isn't resized.

我正在 Android 上构建,并且 this page表示 Android 基线密度为 160dpi 或 mdpi

那么...这是否意味着 MAUI 自动为 ldpi、hdpi、xhdpi、xxhdpi、xxxhdpi 创建图像?

但是...这是否意味着图像会在更高的屏幕密度上出现像素化?

如果将上面的图像定义为最高屏幕密度,然后在不损失质量的情况下缩小到较低密度,不是更有意义吗?

最佳答案

“这不是意味着图像在更高的屏幕密度上会出现像素化吗?”

  • BaseSize 的最佳用途是提供矢量图像,或者至少与最高分辨率一样高分辨率的图像> 你关心的。

那么是的,BaseSize 告诉毛伊岛为不同设备存储什么大小。

  • 如果您有一个 1280 x 1280 的图像,并且知道您将显示的图像不大于两英寸(320 DIP),那么您可以通过指定 BaseSize="320,320"在较低分辨率的设备上节省一些内存

这将在 Density=1 设备上存储 320x320 图像。
将在 Density=4 设备上存储完整的 1280x1280。

  • 您有一个中等尺寸的 png。您可以省略 BaseSize。然后,无论设备如何,您的图像都将“按原样”存储。您的页面布局将指定其呈现的区域。渲染时缩放。

  • 如果您对该图像使用 BaseSize,请使用“绘画”编辑器用透明像素填充边缘,使其可被 8 整除。

  • 我不知道毛伊岛是否曾经为高密度设备存储过放大图像(比原始图像大)。我希望不是;它能够在渲染图像时进行缩放,因此逻辑实现是在这种情况下存储原始图像。

关于android - 了解 MauiImage BaseSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75039244/

相关文章:

visual-studio-2022 - Visual Studio 2022 : prevent collapsing folders in solution explorer (2)

c# - 在 resharper intellisense 中显示枚举整数值

maui - 如何动态地将代码隐藏的选项卡添加到 Maui Shell TabBar?

dependency-injection - 在 MAUI 应用程序中,如何在 AppShell 中使用依赖注入(inject)

c++ - if constexpr std::is_same 在 VS 2022 下

file-io - 如何在MAUI中 bundle 文件?

android - 根据哪个 Activity 包含 fragment 执行 Intent

当使用viewpagers显示软键盘时android向上移动布局

android - 安装 Micello Android SDK

android - 在共享元素 Activity 转换中为嵌套 View 设置动画时出现故障?