主题
BlendMode 继承自: Enum
绘制时用于合并源像素与目标像素的算法。
源(source)指正在绘制的内容,目标(destination)指其背后已存在的内容。
示例
python
import flet as ft
def showcase_card(blend_mode: ft.BlendMode) -> ft.Container:
return ft.Container(
width=280,
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(blend_mode.name, weight=ft.FontWeight.BOLD),
ft.Image(
src="https://picsum.photos/id/237/200/300",
width=240,
height=130,
fit=ft.BoxFit.COVER,
color=ft.Colors.LIGHT_GREEN_200,
color_blend_mode=blend_mode,
border_radius=8,
),
],
),
)
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.appbar = ft.AppBar(title="BlendMode Showcase")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Text("Compare color blending results for each BlendMode value."),
ft.Row(
wrap=True,
spacing=12,
expand=True,
scroll=ft.ScrollMode.AUTO,
alignment=ft.MainAxisAlignment.CENTER,
controls=[
showcase_card(blend_mode) for blend_mode in ft.BlendMode
],
),
]
)
)
)
if __name__ == "__main__":
ft.run(main)枚举值
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
CLEAR | — | 'clear' | Drops both the source and destination, leaving a fully transparent result. |
COLOR | — | 'color' | Takes the hue and saturation from the source and the luminosity from the destination. |
COLOR_BURN | — | 'colorBurn' | Darkens the destination by dividing the inverse destination by the source and then inverting the result. |
COLOR_DODGE | — | 'colorDodge' | Brightens the destination by dividing it by the inverse of the source. |
DARKEN | — | 'darken' | Chooses the darker value from each source and destination color channel. |
DIFFERENCE | — | 'difference' | Subtracts the smaller channel value from the larger one. Compositing black has no effect, while compositing white inverts the other image. |
DST | — | 'dst' | Drops the source and keeps only the destination. |
DST_A_TOP | — | 'dstATop' | Draws the destination over the source, but only where they overlap. |
DST_IN | — | 'dstIn' | Keeps the destination only where the source and destination overlap. The source acts as an opacity mask. |
DST_OUT | — | 'dstOut' | Keeps the destination only where the source and destination do not overlap. The source acts as an opacity mask. |
DST_OVER | — | 'dstOver' | Draws the source underneath the destination. |
EXCLUSION | — | 'exclusion' | Produces an effect similar to DIFFERENCE, but softer. |
HARD_LIGHT | — | 'hardLight' | Combines multiply and screen-style blending while favoring the source image. |
HUE | — | 'hue' | Takes the hue from the source and the saturation and luminosity from the destination. |
LIGHTEN | — | 'lighten' | Chooses the lighter value from each source and destination color channel. |
LUMINOSITY | — | 'luminosity' | Takes the luminosity from the source and the hue and saturation from the destination. |
MODULATE | — | 'modulate' | Multiplies the source and destination color channels without multiplying alpha. |
MULTIPLY | — | 'multiply' | Multiplies the source and destination color channels, including alpha. |
OVERLAY | — | 'overlay' | Combines multiply and screen-style blending while favoring the destination image. |
PLUS | — | 'plus' | Adds the source and destination channel values together. This is useful for cross-fading between two images. |
SATURATION | — | 'saturation' | Takes the saturation from the source and the hue and luminosity from the destination. |
SCREEN | — | 'screen' | Multiplies the inverted source and destination values, then inverts the result. This can only produce the same or lighter colors. |
SOFT_LIGHT | — | 'softLight' | Applies a softer lighting effect than OVERLAY. |
SRC | — | 'src' | Drops the destination and keeps only the source. |
SRC_A_TOP | — | 'srcATop' | Draws the source over the destination, but only where they overlap. |
SRC_IN | — | 'srcIn' | Keeps the source only where the source and destination overlap. The destination acts as an opacity mask. |
SRC_OUT | — | 'srcOut' | Keeps the source only where the source and destination do not overlap. The destination acts as an opacity mask. |
SRC_OVER | — | 'srcOver' | Draws the source over the destination. This is the default painting behavior. |
VALUES | — | 'values' | Not a usable blend mode. Warning: This member exists in the Python enum surface but does not map to a runtime blend mode. Do not use it for painting or image composition. |
XOR | — | 'xor' | Uses an exclusive-or composition so overlapping areas become transparent. |