Skip to main content

Picture

Struct Picture 

Source
pub struct Picture {
    pub blob: Option<Vec<u8>>,
    pub ext: String,
    /* private fields */
}
Expand description

一张图片。

Fields§

§blob: Option<Vec<u8>>

图片字节。保存时写入 zip。

§ext: String

扩展名(含 .,如 .png),用于推导 Content-Type。

Implementations§

Source§

impl Picture

Source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self>

从本地文件创建。

§错误
Source

pub fn from_bytes(bytes: impl Into<Vec<u8>>, ext: impl Into<String>) -> Self

从内存创建。

Source

pub fn from_pic(pic: OxmlPic) -> Self

从 oxml OxmlPic 构造(不携带 blob,用于读取路径)。

Source

pub fn pic(&self) -> &OxmlPic

取出 oxml 引用。

Source

pub fn pic_mut(&mut self) -> &mut OxmlPic

取出 oxml 可变引用。

Source

pub fn properties(&self) -> &ShapeProperties

形状属性不可变引用。

Source

pub fn properties_mut(&mut self) -> &mut ShapeProperties

形状属性可变引用。

Source

pub fn set_fill_mode(&mut self, mode: BlipFillMode)

设置图片填充模式(拉伸/平铺/无)。

对应 OOXML <a:stretch> / <a:tile> 元素。 默认为 BlipFillMode::Stretch(拉伸铺满)。

Source

pub fn set_stretch(&mut self)

设置为拉伸填充模式(便捷方法)。

Source

pub fn set_tile( &mut self, tx: Option<i64>, ty: Option<i64>, sx: Option<i32>, sy: Option<i32>, flip: Option<&str>, algn: Option<&str>, )

设置为平铺填充模式。

§参数
  • tx / ty:水平/垂直偏移(EMU),None 表示不设置;
  • sx / sy:水平/垂直缩放(千分比,100000 = 100%),None 表示不设置;
  • flip:翻转模式("none" / "x" / "y" / "xy"),None 表示不设置;
  • algn:对齐方式("tl" / "ctr" / "br" 等),None 表示不设置。
Source

pub fn fill_mode(&self) -> &BlipFillMode

取当前填充模式。

Source

pub fn crop(&mut self, left: i32, top: i32, right: i32, bottom: i32)

裁剪图片(picture.crop_left/top/right/bottom 的复合设置)。

§参数
  • left / top / right / bottom千分比(取值 0..=100000), 表示从原图四边裁掉的占比。如 left=25000 即裁掉左 25%。 对应 python-pptx picture.crop_left = 0.25(库内做一次 ×100000 转换)。
§示例
// 裁掉左 10%、右 10%,保持上下
pic.crop(10_000, 0, 10_000, 0);
Source

pub fn set_crop(&mut self, left: i32, top: i32, right: i32, bottom: i32)

设置裁剪(TODO-044 高阶 API,crop 的 python-pptx 风格别名)。

crop 完全等价,仅方法名对齐 python-pptx picture.set_crop(left, top, right, bottom) 风格。

Source

pub fn clear_crop(&mut self)

清除裁剪(恢复原图)。

Source

pub fn crop_rect(&self) -> Option<(i32, i32, i32, i32)>

取当前裁剪矩形(千分比),未裁剪返回 None

Source

pub fn crop_left(&self) -> i32

取左侧裁剪量(千分比,TODO-044 高阶 API)。

未裁剪时返回 0。

Source

pub fn crop_top(&self) -> i32

取顶部裁剪量(千分比,TODO-044 高阶 API)。

Source

pub fn crop_right(&self) -> i32

取右侧裁剪量(千分比,TODO-044 高阶 API)。

Source

pub fn crop_bottom(&self) -> i32

取底部裁剪量(千分比,TODO-044 高阶 API)。

Source

pub fn set_crop_left(&mut self, left: i32)

设置左侧裁剪量(千分比,TODO-044 高阶 API),保留其它三边。

Source

pub fn set_crop_top(&mut self, top: i32)

设置顶部裁剪量(千分比,TODO-044 高阶 API),保留其它三边。

Source

pub fn set_crop_right(&mut self, right: i32)

设置右侧裁剪量(千分比,TODO-044 高阶 API),保留其它三边。

Source

pub fn set_crop_bottom(&mut self, bottom: i32)

设置底部裁剪量(千分比,TODO-044 高阶 API),保留其它三边。

Source

pub fn set_placeholder(&mut self, ph_idx: u32, ph_type: Option<&str>)

标记本图片为占位符填充(<p:ph type="pic" idx="..."/>)。

§参数
  • ph_idx:占位符 idx(对应版式中 <p:ph idx="N"/> 的 N)。
  • ph_type:占位符类型字符串(通常 "pic",传 None 则不写出 type 属性)。
§示例
use pptx_rs::Presentation;
use pptx_rs::units::Inches;

let mut p = Presentation::new().unwrap();
let counter = p.id_counter();
let s = p.slides_mut().add_slide(counter).unwrap();
// 假设版式有 idx=10 的图片占位符
let mut pic = s.shapes_mut().add_picture("logo.png", Inches(1.0), Inches(1.0), Inches(4.0), Inches(3.0)).unwrap();
pic.set_placeholder(10, Some("pic"));
Source

pub fn clear_placeholder(&mut self)

清除占位符标记(让本图片回到“自由图片“状态)。

Source

pub fn is_placeholder(&self) -> bool

是否为占位符填充。

Source

pub fn ph_idx(&self) -> Option<u32>

占位符 idx(仅当 is_placeholder 为 true 时有意义)。

Source

pub fn ph_type(&self) -> Option<&str>

占位符类型字符串(如 "pic")。

Source

pub fn base64(&self) -> Option<String>

base64 输出当前图片(便于诊断 / 浏览器内嵌)。

Source

pub fn set_video(&mut self, rid: impl Into<String>)

把本图片标记为视频形状(<a:videoFile r:link="..."/>)。

调用后 Pic::write_xml 会在 <p:nvPr> 内写出 <a:videoFile r:link="..."/>, PowerPoint 渲染时会把该 <p:pic> 当作视频形状处理(双击播放)。

§参数
  • rid:媒体 part 的关系 id(指向 /ppt/media/mediaN.mp4)。 该 rid 必须slideN.xml.rels 中的 <Relationship Type=".../video"/> 一致, 由 crate::slide::ShapesMut::add_video 自动分配,或由调用方手动维护。
§与海报帧 rid 的区别
  • 海报帧图片的 r:embed 关系通过 pic_mut().rid 设置(指向 imageN.png);
  • set_video 设置的是视频文件r:link 关系(指向 mediaN.mp4)。 二者独立,互不影响。
§示例
let mut pic = s.shapes_mut().add_picture("poster.png",
    Inches(1.0), Inches(1.0), Inches(4.0), Inches(3.0)).unwrap();
pic.set_video("rIdVideo1");
Source

pub fn set_audio(&mut self, rid: impl Into<String>)

把本图片标记为音频形状(<a:audioFile r:link="..."/>)。

Self::set_video 对称,仅媒体类型不同。

§参数
  • rid:媒体 part 的关系 id(指向 /ppt/media/mediaN.mp3)。
Source

pub fn media_kind(&self) -> Option<&MediaKind>

取当前媒体类型(视频/音频/None)。

返回 None 表示普通图片;Some(MediaKind::Video { rid }) / Some(MediaKind::Audio { rid }) 表示已通过 Self::set_video / Self::set_audio 标记为媒体形状。

Source

pub fn clear_media(&mut self)

清除媒体标记(让本图片回到普通图片状态)。

Trait Implementations§

Source§

impl Clone for Picture

Source§

fn clone(&self) -> Picture

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Picture

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Picture

Source§

fn default() -> Picture

Returns the “default value” for a type. Read more
Source§

impl Shape for Picture

Source§

fn id(&self) -> u32

形状唯一 ID(在所属 slide 内)。 Read more
Source§

fn set_id(&mut self, id: u32)

设置 ID。
Source§

fn name(&self) -> &str

形状名。
Source§

fn set_name(&mut self, name: String)

设置形状名。
Source§

fn shape_type(&self) -> &'static str

形状类型(如 "text_box" / "picture" / …)。 Read more
Source§

fn left(&self) -> Emu

左上角 x(EMU)。
Source§

fn set_left(&mut self, emu: Emu)

设置左上角 x。
Source§

fn top(&self) -> Emu

左上角 y(EMU)。
Source§

fn set_top(&mut self, emu: Emu)

设置左上角 y。
Source§

fn width(&self) -> Emu

宽(EMU)。
Source§

fn set_width(&mut self, emu: Emu)

设置宽。
Source§

fn height(&self) -> Emu

高(EMU)。
Source§

fn set_height(&mut self, emu: Emu)

设置高。
Source§

fn rotation(&self) -> f64

旋转角度(度数,正向顺时针)。 Read more
Source§

fn set_rotation(&mut self, deg: f64)

设置旋转角度。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V