Skip to content

FilterQuality 继承自: Enum

Quality levels for image sampling in Image and DecorationImage objects.

示例 ​

python
import flet as ft

IMAGE_URL = "https://picsum.photos/id/1025/64/64"


def showcase_card(quality: ft.FilterQuality) -> ft.Container:
    return ft.Container(
        width=300,
        padding=12,
        border=ft.Border.all(1, ft.Colors.RED),
        border_radius=10,
        bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
        content=ft.Column(
            spacing=8,
            controls=[
                ft.Text(quality.name, weight=ft.FontWeight.BOLD),
                ft.Container(
                    width=240,
                    height=120,
                    border=ft.Border.all(1, ft.Colors.OUTLINE),
                    border_radius=8,
                    clip_behavior=ft.ClipBehavior.HARD_EDGE,
                    bgcolor=ft.Colors.SURFACE,
                    content=ft.Image(
                        src=IMAGE_URL,
                        width=240,
                        height=120,
                        fit=ft.BoxFit.FILL,
                        filter_quality=quality,
                    ),
                ),
            ],
        ),
    )


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    page.appbar = ft.AppBar(title="FilterQuality Showcase")
    page.add(
        ft.SafeArea(
            content=ft.Column(
                controls=[
                    ft.Text(
                        "Compare image sampling quality while scaling the "
                        "same source image."
                    ),
                    ft.Row(
                        wrap=True,
                        spacing=12,
                        expand=True,
                        scroll=ft.ScrollMode.AUTO,
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[
                            showcase_card(quality) for quality in ft.FilterQuality
                        ],
                    ),
                ],
            ),
        )
    )


if __name__ == "__main__":
    ft.run(main)

枚举值 ​

名称类型默认值说明
NONE—'none'The fastest filtering method, albeit also the lowest quality.
LOW—'low'Better quality than none, faster than medium.
MEDIUM—'medium'The best all around filtering method that is only worse than high at extremely large scale factors.
HIGH—'high'Best possible quality when scaling up images by scale factors larger than 5-10x. When images are scaled down, this can be worse than medium for scales smaller than 0.5x, or when animating the scale factor. This option is also the slowest.

关注我,学习大模型、大数据、Python等热门技术。