Add support for transarent png images
This commit is contained in:
@@ -6,19 +6,20 @@ pub struct Color {
|
||||
r: u8,
|
||||
g: u8,
|
||||
b: u8,
|
||||
a: u8,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
/// Constructor.
|
||||
///
|
||||
/// The color channels must be between 0 and 255.
|
||||
pub fn from(r: u8, g: u8, b: u8) -> Color {
|
||||
Color { r, g, b }
|
||||
pub fn from(r: u8, g: u8, b: u8, a: u8) -> Color {
|
||||
Color { r, g, b, a}
|
||||
}
|
||||
|
||||
/// Get a hexadecimal representation of the color,
|
||||
/// such as `FFFFFF` for white and `FF0000` for red.
|
||||
pub fn as_hex(self) -> String {
|
||||
format!("{:02X}{:02X}{:02X}", self.r, self.g, self.b)
|
||||
format!("{:02X}{:02X}{:02X}{:02X}", self.r, self.g, self.b, self.a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ impl Painter {
|
||||
}
|
||||
|
||||
// Get an RGB image
|
||||
let image = self.image.as_mut().unwrap().to_rgb();
|
||||
let image = self.image.as_mut().unwrap().to_rgba();
|
||||
|
||||
// Loop through all the pixels, and set their color
|
||||
for x in 0..self.area.w {
|
||||
@@ -68,7 +68,8 @@ impl Painter {
|
||||
let channels = pixel.channels();
|
||||
|
||||
// Define the color
|
||||
let color = Color::from(channels[0], channels[1], channels[2]);
|
||||
let color = Color::from(channels[0], channels[1], channels[2], channels[3]);
|
||||
|
||||
|
||||
// Set the pixel
|
||||
if let Some(client) = &mut self.client {
|
||||
|
||||
Reference in New Issue
Block a user