Skip to content

How to flip an image #2978

Answered by mkj-stonehill
mwpowellhtx asked this question in Q&A
Aug 21, 2024 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

I literally just figured out how to do this today. Here's a function that will flip a bitmap horizontally:

public void Flip(SKBitmap bmp)
{
    // Create a canvas to draw into the bitmap
    using var canvas = new SKCanvas(bmp);

    // Set a transform matrix which moves the bitmap to the right,
    // and then "scales" it by -1, which just flips the pixels
    // horizontally
    canvas.Translate(bmp.Width, 0);
    canvas.Scale(-1, 1);
    canvas.DrawBitmap(bmp, 0, 0);
    return;
}

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@mwpowellhtx
Comment options

@mwpowellhtx
Comment options

@mkj-stonehill
Comment options

@mwpowellhtx
Comment options

@mwpowellhtx
Comment options

Answer selected by mwpowellhtx
Comment options

You must be logged in to vote
1 reply
@mwpowellhtx
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants