How to make the SKBitmap bitmap color as Transparent in SkiaSharp

2,295 views
Skip to first unread message

Mohan Selvaraj

unread,
Feb 15, 2018, 6:26:49 AM2/15/18
to skia-discuss

In System.Drawing we will make the bitmap image color as transparent by using maketransparent method Whether SKBITMAP has any other equivalent method for making the color to transparent.

Bitmap imgData = new Bitmap()
imgData.MakeTransparent(Color.White);//in system.Drawing

In System.Drawing we retrieve the PixelFormat from Image object, but SkiaSharp.SkImage does not provide API to find the PixelFormat of decoded image. Whether it has any other workaround to find the PixelFormat of decoded images and also how can we create Image with PixelFormat value as equivalent of System.Drawing.Image

Can any one please suggest a solution for this?

Matthew Leibowitz

unread,
Feb 19, 2018, 3:43:34 PM2/19/18
to skia-discuss
I am not sure of all the combos that could be used, but something could be done in the lines of:

    SkBitmap bmp = new SkBitmap(original.width(), original.height());
    SkCanvas cnv = new SkCanvas(bmp);
    
    SkPaint paint = new SkPaint();
    paint.SetSomeProperty = SomeValue; // maybe a color filter, mask filter, image filter, blend mode
    
    cnv.drawBitmap(original, 0, 0, paint);

The real question might be that you want to draw an image, but make one color transparent (or just don't draw a specific color)

Maybe the skia gurus can help with this case?

Matthew Leibowitz

unread,
Feb 19, 2018, 3:45:46 PM2/19/18
to skia-discuss
If you have a specific image type - such a an image that is black or white and has some color as a background - like the old-school icons that used that awful purpe to represent transparent. If this is the case, then you should be able to draw the bitmap using a color filter with a blend mode of subtraction or difference...
Reply all
Reply to author
Forward
0 new messages