Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mode=crop and mode=stretch give the same result. #2

Open
bahtiyarozdere opened this issue Feb 17, 2020 · 4 comments
Open

mode=crop and mode=stretch give the same result. #2

bahtiyarozdere opened this issue Feb 17, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@bahtiyarozdere
Copy link

bahtiyarozdere commented Feb 17, 2020

Thanks for great package. Crop and stretch modes are giving the same result.
Crop does not work properly I guess :)

if ((float)resizeParams.w / original.Width < resizeParams.h / original.Height) // crop sides should be inverted I guess.

@keyone2693 keyone2693 added the bug Something isn't working label Feb 17, 2020
@keyone2693
Copy link
Owner

Thanks for great package. Crop and stretch modes are giving the same result. Crop does not work properly I guess :)

if ((float)resizeParams.w / original.Width < resizeParams.h / original.Height) // crop sides should be inverted I guess.

cat u try with version 3

@tukao89
Copy link

tukao89 commented Jun 28, 2024

same error, please fix v3

@tukao89
Copy link

tukao89 commented Jun 28, 2024

Thanks for great package. Crop and stretch modes are giving the same result. Crop does not work properly I guess :)

if ((float)resizeParams.w / original.Width < resizeParams.h / original.Height) // crop sides should be inverted I guess.

did you fix it?

@tukao89
Copy link

tukao89 commented Jun 28, 2024

`internal static SKBitmap CropImage(SKBitmap original, ResizeParams resizeParams)
{
int cropWidth = original.Width;
int cropHeight = original.Height;

// calculate amount of pixels to remove from sides and top/bottom
if ((float)resizeParams.w / original.Width < (float)resizeParams.h / original.Height) // crop sides
{
    cropWidth = (int)Math.Round((float)original.Height / resizeParams.h * resizeParams.w);
}
else // crop top/bottom
{
    cropHeight = (int)Math.Round((float)original.Width / resizeParams.w * resizeParams.h);
}

// setup crop rect
int cropX = (original.Width - cropWidth) / 2;
int cropY = (original.Height - cropHeight) / 2;
var cropRect = new SKRectI(cropX, cropY, cropX + cropWidth, cropY + cropHeight);

// crop
SKBitmap bitmap = new SKBitmap(cropRect.Width, cropRect.Height);
original.ExtractSubset(bitmap, cropRect);

return bitmap;

}
`

this will fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants