ImageMobject

限定名称: manim.mobject.types.image\_mobject.ImageMobject

class ImageMobject(filename_or_array, scale_to_resolution=1080, invert=False, image_mode='RGBA', **kwargs)[source]

基类: AbstractImageMobject

从 NumPy 数组或文件中显示图像。

参数:
  • scale_to_resolution (*int*) – 在此分辨率下,图像会逐像素地放置到屏幕上,因此看起来最清晰、效果最好。这是 ImageMobject 的一个自定义参数,这样使用例如 --quality low--quality medium 标志进行场景渲染以加快渲染速度时,不会影响图像在屏幕上的位置。

  • filename_or_array (StrPath | npt.NDArray)

  • invert (bool)

  • image_mode (str)

  • kwargs (Any)

示例

示例: ImageFromArray

../_images/ImageFromArray-1.png
from manim import *

class ImageFromArray(Scene):
    def construct(self):
        image = ImageMobject(np.uint8([[0, 100, 30, 200],
                                       [255, 0, 5, 33]]))
        image.height = 7
        self.add(image)
class ImageFromArray(Scene):
    def construct(self):
        image = ImageMobject(np.uint8([[0, 100, 30, 200],
                                       [255, 0, 5, 33]]))
        image.height = 7
        self.add(image)

改变插值样式

示例: ImageInterpolationEx

../_images/ImageInterpolationEx-1.png
from manim import *

class ImageInterpolationEx(Scene):
    def construct(self):
        img = ImageMobject(np.uint8([[63, 0, 0, 0],
                                        [0, 127, 0, 0],
                                        [0, 0, 191, 0],
                                        [0, 0, 0, 255]
                                        ]))

        img.height = 2
        img1 = img.copy()
        img2 = img.copy()
        img3 = img.copy()
        img4 = img.copy()
        img5 = img.copy()

        img1.set_resampling_algorithm(RESAMPLING_ALGORITHMS["nearest"])
        img2.set_resampling_algorithm(RESAMPLING_ALGORITHMS["lanczos"])
        img3.set_resampling_algorithm(RESAMPLING_ALGORITHMS["linear"])
        img4.set_resampling_algorithm(RESAMPLING_ALGORITHMS["cubic"])
        img5.set_resampling_algorithm(RESAMPLING_ALGORITHMS["box"])
        img1.add(Text("nearest").scale(0.5).next_to(img1,UP))
        img2.add(Text("lanczos").scale(0.5).next_to(img2,UP))
        img3.add(Text("linear").scale(0.5).next_to(img3,UP))
        img4.add(Text("cubic").scale(0.5).next_to(img4,UP))
        img5.add(Text("box").scale(0.5).next_to(img5,UP))

        x= Group(img1,img2,img3,img4,img5)
        x.arrange()
        self.add(x)
class ImageInterpolationEx(Scene):
    def construct(self):
        img = ImageMobject(np.uint8([[63, 0, 0, 0],
                                        [0, 127, 0, 0],
                                        [0, 0, 191, 0],
                                        [0, 0, 0, 255]
                                        ]))

        img.height = 2
        img1 = img.copy()
        img2 = img.copy()
        img3 = img.copy()
        img4 = img.copy()
        img5 = img.copy()

        img1.set_resampling_algorithm(RESAMPLING_ALGORITHMS["nearest"])
        img2.set_resampling_algorithm(RESAMPLING_ALGORITHMS["lanczos"])
        img3.set_resampling_algorithm(RESAMPLING_ALGORITHMS["linear"])
        img4.set_resampling_algorithm(RESAMPLING_ALGORITHMS["cubic"])
        img5.set_resampling_algorithm(RESAMPLING_ALGORITHMS["box"])
        img1.add(Text("nearest").scale(0.5).next_to(img1,UP))
        img2.add(Text("lanczos").scale(0.5).next_to(img2,UP))
        img3.add(Text("linear").scale(0.5).next_to(img3,UP))
        img4.add(Text("cubic").scale(0.5).next_to(img4,UP))
        img5.add(Text("box").scale(0.5).next_to(img5,UP))

        x= Group(img1,img2,img3,img4,img5)
        x.arrange()
        self.add(x)

方法

淡化

使用 1 - alpha 的关系设置图像的不透明度。

get_pixel_array

一个简单的获取器方法。

get_style

插值颜色

将一个 ImageMobject 的像素颜色值数组插值到目标 ImageMobject 中相同大小的数组。

设置颜色

条件是一个接受一个参数 (x, y, z) 的函数。

set_opacity

设置图像的不透明度。

属性

animate (动画)

用于动画化 self 的任何方法的应用。

animation_overrides (动画覆盖)

depth (深度)

mobject 的深度。

height (高度)

mobject 的高度。

width (宽度)

mobject 的宽度。

_original__init__(filename_or_array, scale_to_resolution=1080, invert=False, image_mode='RGBA', **kwargs)

初始化自身。有关准确签名,请参阅 help(type(self))。

参数:
  • filename_or_array (StrPath | npt.NDArray)

  • scale_to_resolution (int)

  • invert (bool)

  • image_mode (str)

  • kwargs (Any)

返回类型:

fade(darkness=0.5, family=True)[source]

使用 1 - alpha 的关系设置图像的不透明度。

参数:
  • darkness (*float*) – 对象的 alpha 值,1 表示透明,0 表示不透明。

  • family (*bool*) – ImageMobject 的子对象是否应受影响。

返回类型:

自身

get_pixel_array()[source]

一个简单的获取器方法。

interpolate_color(mobject1, mobject2, alpha)[source]

将一个 ImageMobject 的像素颜色值数组插值到目标 ImageMobject 中相同大小的数组。

参数:
  • mobject1 (ImageMobject) – 源 ImageMobject。

  • mobject2 (ImageMobject) – 目标 ImageMobject。

  • alpha (*float*) – 用于跟踪线性插值关系。与不透明度无关。

返回类型:

set_color(color, alpha=None, family=True)[source]

条件是一个函数,它接受一个参数 (x, y, z)。这里它只是递归地作用于子对象,但在子类中,这应该根据颜色的内部工作原理进一步实现。

set_opacity(alpha)[source]

设置图像的不透明度。

参数:

alpha (*float*) – 对象的 alpha 值,1 表示不透明,0 表示透明。

返回类型:

自身