pub trait BufferGetAlpha<P, Container>{
// Required method
fn get_alpha(&self) -> Option<Self>
where Self: Sized;
}
Required Methods§
Sourcefn get_alpha(&self) -> Option<Self>where
Self: Sized,
fn get_alpha(&self) -> Option<Self>where
Self: Sized,
Get the alpha channel of this image as a grayscale with the same number of channels as the input image. (i.e a 4 channel rgba image will return a 3 channel rgba grayscale image)
The alpha channel of the returned image is set to the maximum value of the input type.
If the image does not have an alpha channel, return None.
§Examples
use image::open;
use image_blend::{BufferGetAlpha, BufferSetAlpha};
// Load an image and get its alpha channel
let img1_dynamic = open("test_data/1.png").unwrap();
let img1_buffer = img1_dynamic.as_rgba8().unwrap();
let img1_alpha = img1_buffer.get_alpha().unwrap();
img1_alpha.clone().save("tests_out/doctest_buffer_getalpha_alpha.png").unwrap();
// Load another image and set its alpha channel to the first image's alpha channel, using the copied alpha channel
let mut img2_dynamic = open("test_data/2.png").unwrap();
let mut img2_buffer = img2_dynamic.to_rgba16();
img2_buffer.set_alpha(&img1_alpha).unwrap();
img2_buffer.save("tests_out/doctest_buffer_getalpha_result.png").unwrap();