locked
Image division with SKIASHARP RRS feed

  • Question

  • User391493 posted

    If there is an image of 256256, I would like to divide that image into 4 and arrange each with a size of 256256.

    for (int y = 0; y <= 1; y++)
    {
        for (int x = 0; x <= 1; x++)
        {
    
            int width = bitmap.Width / 2;
            int height = bitmap.Height / 2;
    
            SKRect dest = new SKRect(0, 0, width, height);
            SKRect source = new SKRect(bitmap.Width * x, bitmap.Height * y, bitmap.Width * (x + 1) , bitmap.Height * (y + 1));
    
            canvas.DrawBitmap(bitmap, source, dest);
    
        }
    }
    
    Wednesday, June 10, 2020 1:07 AM

Answers

  • User371688 posted

    You can refer to the official document : https://docs.microsoft.com/en-gb/xamarin/xamarin-forms/user-interface/graphics/skiasharp/bitmaps/cropping#converting-to-xamarinforms-bitmaps

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 11, 2020 9:43 AM

All replies

  • User371688 posted

    You can try the following code:

            int num1;
            int num2;
            float x;
            float y;
    
            for (num1 = 0, y = 0; y < info.Height && num1 < 2; y += bitmap.Height, num1++)
                for (num2 = 0, x = 0; x < info.Width && num2 < 2; x += bitmap.Width, num2++)
                {
                    canvas.DrawBitmap(bitmap, x, y);
                }
    

    The result is:

    Wednesday, June 10, 2020 9:03 AM
  • User391493 posted

    For example, if you have a 256×256 size monkey image,

    first divide the 256×256 image into 4. (4 images of 128×128 can be made)

    Next, expand the 4 divided images to 256×256 and arrange them.

    Wednesday, June 10, 2020 9:30 AM
  • User371688 posted

    You can refer to the official document : https://docs.microsoft.com/en-gb/xamarin/xamarin-forms/user-interface/graphics/skiasharp/bitmaps/cropping#converting-to-xamarinforms-bitmaps

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, June 11, 2020 9:43 AM