Steven Mark Ford
Steven Mark Ford

Reputation: 3432

Using SkiaSharp how would one darken the entire image (excluding the background)

The below snippet darkens the entire image but I wish to darken all the parts except the background. How would one go about doing this? You will notice the png below has no background so I am not sure why this doesn't work.

I am guessing it is something to do with how the image is loaded into memory from the file and alpha channels etc.

 SKImage image = SKImage.FromBitmap(resourceBitmap);

 var skImageFilter = SKImageFilter.CreateColorFilter(SKColorFilter.CreateBlendMode(AppColors.DarkGreyColor.ToSKColor(),
                SKBlendMode.Darken));



 image = image.ApplyImageFilter(
                skImageFilter, new SKRectI(0,0, image.Width,image.Height), new SKRectI(0, 0, image.Width, image.Height), out SKRectI subSet, out SKPoint point);

enter image description here

Upvotes: 1

Views: 757

Answers (1)

Dresel
Dresel

Reputation: 2395

This is possible by wrapping the SKImageFilter, taken from this other stack overflow question:

SKImageFilter.CreateBlendMode(SKBlendMode.DstIn,
    SKImageFilter.CreateColorFilter(SKColorFilter.CreateBlendMode(AppColors.DarkGreyColor.ToSKColor(), SKBlendMode.Darken)));

Upvotes: 1

Related Questions