SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[BUG] SkCanvas Crop not Proper Working ?

Open Hardikzinzala opened this issue 2 years ago • 1 comments

Description

I give height and width with x and y of my element but Skcanvas doesn't crop to my values

Code

frame is a Frame Element in .Net Maui

Rectangle frameBounds = new Rectangle((int)frame.X, (int)frame.Y, (int)frame.Width, (int)frame.Height);

croppedImage = ImageUtils.CropImage1(sourceImage,frameBounds);

public static SKBitmap CropImage1(SKBitmap sourceImage, Rectangle frameBounds) { SKBitmap croppedBitmap = new SKBitmap((int)frameBounds.Height, (int)frameBounds.Width); SKRect destRect = new SKRect(0, 0, croppedBitmap.Width, croppedBitmap.Height); SKRect sourceRect = new SKRect(frameBounds.Left3, frameBounds.Top3, frameBounds.Right3, frameBounds.Bottom4);

using (SKCanvas canvas = new SKCanvas(croppedBitmap))
{
    canvas.DrawBitmap(sourceImage, sourceRect, destRect);
}

return croppedBitmap;

}

Expected Behavior

No response

Actual Behavior

No response

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

All

Platform / Operating System Version

Android 13

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Hardikzinzala avatar Nov 28 '23 05:11 Hardikzinzala

I've got a similar issue, but it seems to depend on the bitmap image,

var destRect = new SKRect(x, y, x + scale * bm.Width, y + scale * bm.Height); var skRound = new SKRoundRect(destRect, 10); canvas.ClipRoundRect(skRound); canvas.DrawBitmap(bm, destRect);

I have no idea what I should look into to find out why 1 image the code doesn't work but it works for others. especially when said image/bitmap only has issues on android(works excellently on windows and iOS).

Swodah avatar Feb 08 '24 09:02 Swodah