SKBitmap manipulation issue in Xamarin.Forms with SkiaSharp

57 Views Asked by At

I'm working on a Xamarin.Forms project and utilizing SkiaSharp for bitmap manipulation. I have a code snippet that directly manipulates an SKBitmap obtained from an ImageButton source, and it works as expected:

canvas.DrawBitmap(SKBitmap.Decode(picturebox.Source.ToString()), new SKRect((float)lastMousePosition.X - pixell, (float)lastMousePosition.Y - pixell, (float)lastMousePosition.X - pixell + pixell * 2, (float)lastMousePosition.Y - pixell + pixell * 2), new SKRect((float)lastMousePosition.X - pixel, (float)lastMousePosition.Y - pixel, (float)lastMousePosition.X - pixel + pixel * 2, (float)lastMousePosition.Y - pixel + pixel * 2), paint);

However, when I attempt a similar manipulation using a method (aaaa) to process an SKBitmap obtained from an ImageButton within a StackLayout, it doesn't produce the expected result:

((StackLayout)scrol.Content).Children[b] = aaaa(SKBitmap.Decode(((ImageButton)((StackLayout)scrol.Content).Children[b]).Source), opacity, (int)e.TotalX - int.Parse(ll3[0]), (int)e.TotalY - int.Parse(ll3[1]), size);

Here's the aaaa method:

private SKBitmap aaaa(SKBitmap inputImage, float strength, int brushSize, int brushLocation, int radius)
{
    
}

I've confirmed that the aaaa method is receiving the SKBitmap correctly, but the result is unexpected. Could you please help me understand what might be causing this discrepancy? Any insights or suggestions would be greatly appreciated.

Thank you!

1

There are 1 best solutions below

1
On

I figured out that i need to assign it first instead of using it constantly.

for example:

ImageButton sss = ((StackLayout)scrol.Content).Children[b] as ImageButton;