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]

进行数据对齐,以便插值

cmpt_init_datas = {'color': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.ImageItem'>), 'depth': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.item.Item'>), 'image': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.ImageItem'>), 'points': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.points.Points'>)}
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 基本一致,只是在图像被放大显示时不进行平滑插值处理,使得像素清晰

cmpt_init_datas = {'color': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.ImageItem'>), 'depth': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.item.Item'>), 'image': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.ImageItem'>), 'points': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.points.Points'>)}
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
cmpt_init_datas = {'color': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.ImageItem'>), 'depth': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.item.Item'>), 'image': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.ImageItem'>), 'points': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.points.Points'>)}
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)

基类:Points

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

控制视频播放的方法:

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

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

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

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

例:

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()

start(*, speed: int = 1) None
stop() None
seek(t: float) None
compute_time(t: float) None
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]

进行数据对齐,以便插值

cmpt_init_datas = {'color': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.Video'>), 'depth': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.item.Item'>), 'points': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.points.Points'>)}
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 基本一致,只是在被放大显示时不进行平滑插值处理,使得像素清晰

cmpt_init_datas = {'color': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.image_item.Video'>), 'depth': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.item.Item'>), 'points': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.points.Points'>)}