jay3332/ril

Removing white background

weiying-chen opened this issue · 1 comments

Currently, is there a way to remove, say, the white background of the drawing of a dog? In other words, make the background go from white to transparent without affecting the dog?

This is not something built directly into RIL since the implementation for removing backgrounds from images varies from user to user.

If your goal is to just turn all white pixels into transparent pixels, you can try something like:

let mut image = Image::<Rgba>::open("dog.png");
image.map_in_place(|_, _, pixel| {
    if pixel.as_rgb_tuple() == (255, 255, 255) { 
        *pixel = Rgba::transparent();
    }
});