图像对象¶
限定名称: manim.mobject.types.image\_mobject.ImageMobject
- class ImageMobject(filename_or_array, scale_to_resolution=1080, invert=False, image_mode='RGBA', **kwargs)[source]¶
基础类:
AbstractImageMobject显示来自numpy数组或文件的图像。
- Parameters:
scale_to_resolution (int) – 在此分辨率下,图像将逐像素放置在屏幕上,因此它将看起来最清晰和最佳。 这是ImageMobject的自定义参数,以便在使用例如
--quality low或--quality medium标志进行更快渲染的场景时,不会影响图像在屏幕上的位置。
示例
示例:ImageFromArray ¶
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 ¶
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关系设置图像的不透明度。
一个简单的getter方法。
get_style将一个ImageMobject中的像素颜色值数组插值到目标ImageMobject中大小相同的数组中。
条件是一个函数,它接受一个参数,(x, y, z)。
设置图像的不透明度。
属性
animate用于动画化
self的任何方法的应用。animation_overridesdepthmobject的深度。
heightmobject的高度。
widthmobject的宽度。
- _original__init__(filename_or_array, scale_to_resolution=1080, invert=False, image_mode='RGBA', **kwargs)¶
初始化自身。有关准确的签名,请参阅 help(type(self))。
- Parameters:
scale_to_resolution (int)
- fade(darkness=0.5, family=True)[source]¶
使用1 - alpha关系设置图像的不透明度。
- Parameters:
darkness (float) – 对象的alpha值,1表示透明,0表示不透明。
family (bool) – ImageMobject 的子对象是否应该受到影响。
- interpolate_color(mobject1, mobject2, alpha)[来源]¶
将一个ImageMobject的像素颜色值数组插值到目标ImageMobject中大小相同的数组中。
- Parameters:
mobject1 (ImageMobject) – 要从中转换的ImageMobject。
mobject2 (ImageMobject) – 要转换成的ImageMobject。
alpha (float) – 用于跟踪lerp关系。与不透明度无关。