简体   繁体   English

如何使用 ImageSharp/C# 垂直翻转图像

[英]How to flip an image vertically using ImageSharp/C#

Because Y-axis is inverted I would like to flip my resulting image vertically.因为 Y 轴是倒置的,所以我想垂直翻转生成的图像。 垂直翻转

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.我还没有理解 FlipExtensions 和 FlipMode 在 ImageSharp 中的工作原理,也许甚至无法使用它来翻转我的图像。

How am I supposed to do?我该怎么办?

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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM