Skip to main content

ImageObject

Struct ImageObject 

Source
pub struct ImageObject {
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub data: Vec<u8>,
    pub format: ImageFormat,
    pub res_name: Option<String>,
}
Expand description

带位置和尺寸的图片对象。

Fields§

§x: f64

距左边缘的 X 位置(mm)。

§y: f64

距顶部的 Y 位置(mm)。

§width: f64

宽度(mm)。

§height: f64

高度(mm)。

§data: Vec<u8>

图片数据(原始字节)。

§format: ImageFormat

图片格式。

§res_name: Option<String>

原始资源路径(相对文档目录,如 "Res/qrcode.png")。

读取 OFD 文件时保留,写入器优先使用该路径而非自动命名, 从而在 roundtrip 时保持图片资源名与原始文件一致。

Implementations§

Source§

impl ImageObject

Source

pub fn new( x: f64, y: f64, width: f64, height: f64, data: Vec<u8>, format: ImageFormat, ) -> Self

创建新的图片对象。

Source

pub fn with_res_name(self, res_name: impl Into<String>) -> Self

设置原始资源路径(roundtrip 保留图片名时使用)。

Source

pub fn jpeg(x: f64, y: f64, width: f64, height: f64, data: Vec<u8>) -> Self

创建 JPEG 图片对象。

Source

pub fn png(x: f64, y: f64, width: f64, height: f64, data: Vec<u8>) -> Self

创建 PNG 图片对象。

Source

pub fn from_file( x: f64, y: f64, width: f64, height: f64, path: impl AsRef<Path>, ) -> OfdResult<Self>

从文件路径创建图片对象,自动检测格式。

从以下信息检测格式:

  • 文件扩展名(.jpg/.jpeg → Jpeg, .png → Png, .bmp → Bmp, .tiff/.tif → Tiff)
  • 魔术字节(扩展名不明确时的回退方案)
§错误

文件无法读取或格式不支持时返回错误。

Trait Implementations§

Source§

impl Clone for ImageObject

Source§

fn clone(&self) -> ImageObject

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 ImageObject

Source§

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

Formats the value using the given formatter. Read more

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<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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.