Manim关于图片的操作。

1. 添加一张外部图片

Marim使用类ImageMobject来创建一张图片,

# Displays an Image from a numpy array or a file.
class ImageMobject(filename_or_array, scale_to_resolution=1080, invert=False, image_mode='RGBA', **kwargs)

# Example
image= ImageMobject("images/test.png")
height = image.height
width = image.width

可以通过image.widthimage.height获取图片的宽度和高度,再配合缩放函数,调整图片的大小以适合屏幕的尺寸。

# Scale the size by a factor. Default behavior is to scale about the center of the mobject.
scale(scale_factor, **kwargs)

# Scales the Mobject to fit a width while keeping height/depth proportional.
scale_to_fit_width(width, **kwargs)
scale_to_fit_height(height, **kwargs)
scale_to_fit_depth(depth, **kwargs)

有个小疑问,比如我用一张225x225x8的图片创建ImageMobject对象,但输出的宽度和高度均为1.6666666666666667,这个是怎么换算的?

2. 将Manim对象保存为图片

save_image将一个Mobject保存为png图片,举例:

squre = Square()
squre.save_image('test')

3. 将一帧保存为图片

目前只找到,保存最后一帧的方法:在配置文件,将save_last_frame设为True

from manim import *

config.save_last_frame = True     # OR
config['save_last_frame'] = True

在寻求一种方法,可以在代码任意位置,保存当下帧为图片。

4. 将动画保存为gif

在配置文件,将save_as_gif设为True

from manim import *

config.save_as_gif = True     # OR
config['save_as_gif'] = True
本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-02-26 22:25

results matching ""

    No results matching ""