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¶
- 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_vertical_vect() ndarray¶
从图像的左上角指向左下角的向量
- get_vertical_dist() float¶
- 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)¶
-
视频物件,和图像物件类似,其实本质上是一个内容实时变化的图像
控制视频播放的方法:
和其它物件一样,使用
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_vertical_vect() ndarray¶
从视频的左上角指向左下角的向量
- get_vertical_dist() float¶
- 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