Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

DrawBitmap not working

Hi

I have this image, 200x200 pixels.

I want to draw part of the image, for example, Part #2 or # 3.
I can only draw part #1.

canvas.DrawBitmap(bitmap, new SKRect(0, 0, 100, 100), new SKRect(0, 0, 100, 100)); // #1

when I try to draw other parts, nothing appears.
How can I do that?
Thank you in advance

Tagged:

Best Answer

  • PaulNTUPaulNTU USMember ✭✭✭
    edited May 2019 Accepted Answer

    You havent provided your code for the problem areas so its difficult to see what's wrong

    the first SKRect is your source rectangle (What part of the image to draw from your source) and the second is your destination (Where to draw onto the new bitmap)

    Try these commands

    // Draw #1 to #2
    canvas.DrawBitmap(bitmap, new SKRect(0, 0, 100, 100), new SKRect(100, 0, 200, 100)); 
    
    // Draw #1 to #3
    canvas.DrawBitmap(bitmap, new SKRect(0, 0, 100, 100), new SKRect(0, 100, 100, 200)); 
    

    HTH
    Paul

Answers

  • PaulNTUPaulNTU USMember ✭✭✭
    edited May 2019 Accepted Answer

    You havent provided your code for the problem areas so its difficult to see what's wrong

    the first SKRect is your source rectangle (What part of the image to draw from your source) and the second is your destination (Where to draw onto the new bitmap)

    Try these commands

    // Draw #1 to #2
    canvas.DrawBitmap(bitmap, new SKRect(0, 0, 100, 100), new SKRect(100, 0, 200, 100)); 
    
    // Draw #1 to #3
    canvas.DrawBitmap(bitmap, new SKRect(0, 0, 100, 100), new SKRect(0, 100, 100, 200)); 
    

    HTH
    Paul

Sign In or Register to comment.