pub struct Bounds { /* private fields */ }Expand description
Rectangle bounds for defining sub-regions of images.
Implementations§
Source§impl Bounds
impl Bounds
Sourcepub fn new(x: Pt, y: Pt, width: Pt, height: Pt) -> Self
pub fn new(x: Pt, y: Pt, width: Pt, height: Pt) -> Self
Creates new bounds with the specified dimensions.
Examples found in repository?
examples/subimage_example.rs (line 22)
10 fn initialize(_context: &mut Context) -> Self {
11 const TREE_PNG: &[u8] = include_bytes!("../assets/happy-tree.png");
12 let decoded = image::load_from_memory(TREE_PNG).expect("failed to decode happy-tree.png");
13 let rgba = decoded.to_rgba8();
14 let (w, h) = (rgba.width(), rgba.height());
15 let tree = Image::new_from_rgba8(Pt::from(w), Pt::from(h), rgba.as_raw())
16 .expect("failed to create happy-tree image");
17
18 let crop_w = (w / 2).max(1);
19 let crop_h = (h / 2).max(1);
20 let tree_sub = Image::sub_image(
21 tree,
22 Bounds::new(Pt::from(0.0), Pt::from(0.0), Pt::from(crop_w), Pt::from(crop_h)),
23 )
24 .expect("failed to create sub image");
25
26 Self { tree, tree_sub }
27 }More examples
examples/demo.rs (line 33)
12 fn initialize(_context: &mut Context) -> Self {
13 const TREE_PNG: &[u8] = include_bytes!("../assets/happy-tree.png");
14 let decoded = image::load_from_memory(TREE_PNG).expect("failed to decode happy-tree.png");
15 let rgba = decoded.to_rgba8();
16 let (w, h) = (rgba.width(), rgba.height());
17 let tree = Image::new_from_rgba8(Pt::from(w), Pt::from(h), rgba.as_raw())
18 .expect("failed to create happy-tree image");
19
20 let mut rgba = vec![0u8; 20 * 20 * 4];
21 for y in 0..20u32 {
22 for x in 0..20u32 {
23 let i = ((y * 20 + x) * 4) as usize;
24 let on = ((x / 5 + y / 5) % 2) == 0;
25 rgba[i] = if on { 255 } else { 30 };
26 rgba[i + 1] = if on { 80 } else { 200 };
27 rgba[i + 2] = if on { 80 } else { 255 };
28 rgba[i + 3] = 255;
29 }
30 }
31 let image =
32 Image::new_from_rgba8(Pt::from(20.0), Pt::from(20.0), &rgba).expect("failed to create test image");
33 let image_sub = Image::sub_image(image, Bounds::new(Pt::from(5.0), Pt::from(5.0), Pt::from(10.0), Pt::from(10.0)))
34 .expect("failed to create sub image");
35 let image_clone = Image::new_from_image(image).expect("failed to create image from image");
36
37 Self {
38 tree,
39 image,
40 image_sub,
41 image_clone,
42 }
43 }Trait Implementations§
impl Copy for Bounds
impl Eq for Bounds
impl StructuralPartialEq for Bounds
Auto Trait Implementations§
impl Freeze for Bounds
impl RefUnwindSafe for Bounds
impl Send for Bounds
impl Sync for Bounds
impl Unpin for Bounds
impl UnwindSafe for Bounds
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more