I am trying to clear a bitmap in SkiaSharp in Xamarin, the bitmap is drawn by a SkCanvas,
new SKCanvas(SkBitmap bitmap)
but at times i need to clear the bitmap data.
SkCanvas.Clear()
tries to fill the bitmap with SKColor(0,0,0,0) pixels, but premul with the existing pixels it doesn't affect it.
SKBitmap.Reset()
doesnt work because it resets the object completely including the size. Any idea how can i achieve this in an efficient way, not by going through all the pixels?
If you are trying to clear the pixel data, you WILL have to clear each pixel. There is no way around this.
To clear the bitmap/canvas, you should use SKCanvas.Clear()
, but remember, you can pass in a color. So if you want the pixel data to be all zeroes, you can just SKCanvas.Clear(0)
.
I think this is what you are asking, if not I may need more info.
EDIT
Another thing that just occurred is that there is a SKBitmap.Erase(SKColor)
. This may be better as there is no need for a canvas.