Home > Net >  How to flip an image vertically using ImageSharp/C#
How to flip an image vertically using ImageSharp/C#

Time:06-28

Because Y-axis is inverted I would like to flip my resulting image vertically. vertical_flip

Currently this is how my code looks like:

using (MemoryStream outStream = new MemoryStream())
{
  using (Image img = new Image<Rgba32>(width, height))
  {
     PathBuilder pb = drawPath(); // draw Path draws everything

     IPath path = pb.Build();
     path.AsClosedPath();

     img.Mutate(imageContext => imageContext
       .BackgroundColor(Color.Black)
       .Fill(Color.Yellow, path)
     );

     img.SaveAsPng(outStream);
  }
  
  return File(outStream.ToArray(), "image/png");
}

I have not yet understod how the FlipExtensions and FlipMode works in ImageSharp, maybe it's not even possible to use it to flip my image.

How am I supposed to do?

CodePudding user response:

using (MemoryStream outStream = new MemoryStream())
{
  using (Image img = new Image<Rgba32>(width, height))
  {
     PathBuilder pb = drawPath(); // draw Path draws everything

     IPath path = pb.Build();
     path.AsClosedPath();

     img.Mutate(imageContext => imageContext
       .BackgroundColor(Color.Black)
       .Fill(Color.Yellow, path)
     );

     img.RotateFlip(RotateFlipType.Rotate180FlipNone);

     img.SaveAsPng(outStream);
  }
  
  return File(outStream.ToArray(), "image/png");
}

CodePudding user response:

Read this microsoft document. May be it can help you

https://docs.microsoft.com/tr-tr/dotnet/api/system.drawing.image.rotateflip?view=dotnet-plat-ext-6.0

  • Related