Skiasharp Read and Modify Pixels - Improve performance #2434
Closed
mikepasoglou
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to use C sharp and Skiashap to implement image processing in a Blazor webassebly app.
The code below is trying to implement edge detection. The result of the code below is quite good , it needs improving , but this is not my point.
The code below is my first try.
`canvas.Clear(SKColors.White);
// USerskbitmapNEW has been loaded earlier.
SKBitmap image = new SKBitmap(USerskbitmapNEW.Width, USerskbitmapNEW.Height);
for (int i = 0; i < image.Width; i++)
{
for (int j = 0; j < image.Height; j++)
{
SKColor c1 = USerskbitmapNEW.GetPixel(i, j - 1);
SKColor c2 = USerskbitmapNEW.GetPixel(i, j + 1);
int xval = 0;
int yval = 0;
xval = (int)(c1.Red * .3 + c2.Blue * 0.11 - (c2.Red * .3));
yval = (int)(c2.Red * .3 + c2.Green * .29 + c2.Blue * 0.11);
if (xval > yval )
{
SKColor c = SKColors.Black;
image.SetPixel(i, j, c);
}
My problem is that the methods : SKbitmap.GetPixel(i, j); and SKbitmap.SetPixel(i, j, color); are extremely slow when use them with images bigger than 200kb size.
In contrast to the above methods( SKBitmap .GetPixel and SKBitmap .SetPixel) , when you apply image various filters , for example ,
var cf = SKColorFilter.CreateTable(null, null, colorTable, colorTable); ....
skiasharp is very fast.My second try to improve performance , is to use SKPixmap class insted of the method above. So my code looks like the snipset below.
`canvas.Clear(SKColors.White);
In that case the problem is that SKPixmap does not have any method to set the output pixel color accordingly to Skbitmap.Setpixel(x,y,color), so the above code using SKPixmap cant not implement.
My questions for this discussion are:
Is there any other way , using SKPixmap class , to set and modify pixels of the image?
In general for Skiasharp. Is there any other way to read and modily pixels instead of Skbitmap.SetPixel ?
( which is working but with bad performance.)
Thanks in advance
Michalis
Beta Was this translation helpful? Give feedback.
All reactions