image_item

class janim.items.image_item.ImageItem(file_path_or_image: str | Image, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9729), **kwargs)

基类:Points

图像物件

会读取给定的文件路径的图像

renderer_cls

ImageItemRenderer 的别名

image
color
apply_style(color: JAnimColor | ColorArray | None = None, alpha: Alpha | AlphaArray | None = None, **kwargs) Self

设置物件自身的样式,不影响子物件

另见:set()

get_orig() ndarray

图像的左上角

get_horizontal_vect() ndarray

从图像的左上角指向右上角的向量

get_horizontal_dist() float

get_horizontal_vect() 的长度

get_vertical_vect() ndarray

从图像的左上角指向左下角的向量

get_vertical_dist() float

get_vertical_vect() 的长度

pixel_to_rgba(x: int, y: int) ndarray

根据像素坐标得到颜色

point_to_rgba(point: ndarray, clamp_to_edge: bool = False) ndarray

通过空间坐标获得对应的像素颜色

pixel_to_point(x: float, y: float) ndarray

通过像素坐标获得对应的空间坐标,可以传入浮点值

  • 例如 .pixel_to_point(0, 0) 会返回原点位置(图片的左上角)

  • 例如 .pixel_to_point(6, 11) 会返回 (6, 11) 像素的左上角

  • 例如 .pixel_to_point(6.5, 11.5) 会返回 (6, 11) 像素的中心

point_to_pixel(point: ndarray) tuple[int, int]

根据空间坐标得到像素坐标(向图像原点取整)

classmethod align_for_interpolate(item1: ImageItem, item2: ImageItem) AlignedData[ImageItem]

进行数据对齐,以便插值

class janim.items.image_item.PixelImageItem(file_path: str, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9728), **kwargs)

基类:ImageItem

图像物件

ImageItem 基本一致,只是在图像被放大显示时不进行平滑插值处理,使得像素清晰

class janim.items.image_item.VideoFrame(file_path: str, frame_at: str | float, *, width: float | None = None, height: float | None = None, **kwargs)

基类:ImageItem

视频帧,用于提取视频在指定时间处的一帧图像

  • file_path: 文件路径

  • frame_at: 位于哪一帧,可以使用秒数或者 ffmpeg 支持的时间定位方式,例如 17.4'00:01:12'

不建议使用该类将视频提取为多帧以达到“读取视频”的目的,因为这会导致巨大的性能浪费以及内存占用

播放视频请使用 Video

static capture(file_path: str, frame_at: str | float, *, cache: bool = True) Image
class janim.items.image_item.Video(file_path: str, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9729), frame_components: int = 3, **kwargs)

基类:PlaybackControl, Points

视频物件,和图像物件类似,其实本质上是一个内容实时变化的图像

控制视频播放的方法:

  • 和其它物件一样,使用 show() 进行显示,默认暂停在第一帧

  • 调用 start 表示从当前位置开始播放,可以传入 speed 参数指定倍速

  • 调用 stop 表示停止在当前位置

  • 调用 seek 表示跳转视频进度到指定秒数

传入参数:

  • 使用 loop 可控制是否循环播放

  • 如果需要插入带透明通道的视频(如 .mov 视频),需要设置 frame_components=4

注意:在默认情况下未开始播放,需要使用 start 以开始播放

注:可以使用 .info 获取视频如时长等额外信息

例:

video = Video(...).show()

video.start()

self.forward()

video.start(speed=0.5)

self.forward()

video.stop()

表示:先播放 1s,然后以 0.5 倍速播放 1s,然后画面静止

color
renderer_cls

VideoRenderer 的别名

apply_style(color: JAnimColor | ColorArray | None = None, alpha: Alpha | AlphaArray | None = None, **kwargs) Self

设置物件自身的样式,不影响子物件

另见:set()

get_orig() ndarray

视频的左上角

get_horizontal_vect() ndarray

从视频的左上角指向右上角的向量

get_horizontal_dist() float

get_horizontal_vect() 的长度

get_vertical_vect() ndarray

从视频的左上角指向左下角的向量

get_vertical_dist() float

get_vertical_vect() 的长度

pixel_to_point(x: float, y: float) ndarray

通过像素坐标获得对应的空间坐标,可以传入浮点值

  • 例如 .pixel_to_point(0, 0) 会返回原点位置(图片的左上角)

  • 例如 .pixel_to_point(6, 11) 会返回 (6, 11) 像素的左上角

  • 例如 .pixel_to_point(6.5, 11.5) 会返回 (6, 11) 像素的中心

classmethod align_for_interpolate(item1: ImageItem, item2: ImageItem) AlignedData[ImageItem]

进行数据对齐,以便插值

class janim.items.image_item.VideoInfo(file_path: str)

基类:object

class janim.items.image_item.PixelVideo(file_path: str, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9728), **kwargs)

基类:Video

视频物件

Video 基本一致,只是在被放大显示时不进行平滑插值处理,使得像素清晰