当前位置: 首页>>代码示例>>C#>>正文


C# MagickImage.GetPixels方法代码示例

本文整理汇总了C#中ImageMagick.MagickImage.GetPixels方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.GetPixels方法的具体用法?C# MagickImage.GetPixels怎么用?C# MagickImage.GetPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageMagick.MagickImage的用法示例。


在下文中一共展示了MagickImage.GetPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_FillColor

    public void Test_FillColor()
    {
      using (MagickImage image = new MagickImage(MagickColors.Transparent, 100, 100))
      {
        ColorAssert.AreEqual(MagickColors.Black, image.Settings.FillColor);

        Pixel pixelA;
        image.Settings.FillColor = MagickColors.Red;
        image.Read("caption:Magick.NET");

        Assert.AreEqual(100, image.Width);
        Assert.AreEqual(100, image.Height);

        using (PixelCollection pixels = image.GetPixels())
        {
          pixelA = pixels.GetPixel(69, 6);
        }

        Pixel pixelB;
        image.Settings.FillColor = MagickColors.Yellow;
        image.Read("caption:Magick.NET");
        using (PixelCollection pixels = image.GetPixels())
        {
          pixelB = pixels.GetPixel(69, 6);
        }

        ColorAssert.AreNotEqual(pixelA.ToColor(), pixelB.ToColor());
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:29,代码来源:MagickSettingsTests.cs

示例2: AreEqual

 public static void AreEqual(MagickColor expected, MagickImage image, int x, int y)
 {
   using (PixelCollection pixels = image.GetPixels())
   {
     AreEqual(expected, pixels.GetPixel(x, y));
   }
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:7,代码来源:ColorAssert.cs

示例3: TestPixels

    private static void TestPixels(MagickImage image, MagickColor firstRow, MagickColor secondRow)
    {
      using (PixelCollection pixels = image.GetPixels())
      {
        for (int y = 0; y < 2; y++)
          for (int x = 0; x < 10; x++)
            ColorAssert.AreEqual(y == 0 ? firstRow : secondRow, pixels.GetPixel(x, y).ToColor());
      }

      using (MemoryStream memStream = new MemoryStream())
      {
        image.Format = MagickFormat.Bmp;
        image.Write(memStream);
        memStream.Position = 0;

        using (MagickImage output = new MagickImage(memStream))
        {
          using (PixelCollection pixels = output.GetPixels())
          {
            for (int y = 0; y < 2; y++)
              for (int x = 0; x < 10; x++)
                ColorAssert.AreEqual(y == 0 ? firstRow : secondRow, pixels.GetPixel(x, y).ToColor());
          }
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:26,代码来源:PixelCollectionTests.cs

示例4: Test_Read_Bytes

    public void Test_Read_Bytes()
    {
#if Q8
      var bytes = new byte[] { 1, 2, 3, 4 };
#elif Q16 || Q16HDRI
      var bytes = new byte[] { 1, 0, 2, 0, 3, 0, 4, 0 };
#else
#error Not implemented!
#endif

      MagickReadSettings settings = new MagickReadSettings()
      {
        Width = 1,
        Height = 1
      };

      settings.Format = MagickFormat.Bgra;
      using (MagickImage image = new MagickImage(bytes, settings))
      {
        using (PixelCollection pixels = image.GetPixels())
        {
          Pixel pixel = pixels.GetPixel(0, 0);
          Assert.AreEqual(4, pixel.Channels);
          Assert.AreEqual(3, pixel.GetChannel(0));
          Assert.AreEqual(2, pixel.GetChannel(1));
          Assert.AreEqual(1, pixel.GetChannel(2));
          Assert.AreEqual(4, pixel.GetChannel(3));
        }
      }

      settings.Format = MagickFormat.Bgro;
      using (MagickImage image = new MagickImage(bytes, settings))
      {
        using (PixelCollection pixels = image.GetPixels())
        {
          Pixel pixel = pixels.GetPixel(0, 0);
          Assert.AreEqual(4, pixel.Channels);
          Assert.AreEqual(3, pixel.GetChannel(0));
          Assert.AreEqual(2, pixel.GetChannel(1));
          Assert.AreEqual(1, pixel.GetChannel(2));
          Assert.AreEqual(Quantum.Max - 4, pixel.GetChannel(3));
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:44,代码来源:BgrTests.cs

示例5: Test_IndexOutOfRange

    public void Test_IndexOutOfRange()
    {
      using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
      {
        using (PixelCollection pixels = image.GetPixels())
        {
          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetArea(4, 0, 2, 1);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetArea(new MagickGeometry(0, 9, 1, 2));
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetArea(-1, 0, 1, 1);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetArea(0, -1, 1, 1);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetArea(0, 0, -1, 1);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetArea(0, 0, 1, -1);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetValue(5, 0);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetValue(-1, 0);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetValue(0, -1);
          });

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetValue(0, 10);
          });
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:58,代码来源:PixelCollectionTests.cs

示例6: Test_IEnumerable

 public void Test_IEnumerable()
 {
   using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
   {
     using (PixelCollection pixels = image.GetPixels())
     {
       Assert.AreEqual(50, pixels.Count());
     }
   }
 }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:10,代码来源:PixelCollectionTests.cs

示例7: Test_GetValues

    public void Test_GetValues()
    {
      using (MagickImage image = new MagickImage(MagickColors.PowderBlue, 1, 1))
      {
        Assert.AreEqual(3, image.ChannelCount);

        using (PixelCollection pixels = image.GetPixels())
        {
          var values = pixels.GetValues();
          Assert.AreEqual(3, values.Length);

          MagickColor color = new MagickColor(values[0], values[1], values[2]);
          ColorAssert.AreEqual(MagickColors.PowderBlue, color);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:16,代码来源:PixelCollectionTests.cs

示例8: Test_GetValue

    public void Test_GetValue()
    {
      using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
      {
        using (PixelCollection pixels = image.GetPixels())
        {
          var values = pixels.GetValue(0, 0);
          Assert.AreEqual(3, values.Length);

          MagickColor color = new MagickColor(values[0], values[1], values[2]);
          ColorAssert.AreEqual(MagickColors.Red, color);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:14,代码来源:PixelCollectionTests.cs

示例9: Test_GetArea

    public void Test_GetArea()
    {
      using (MagickImage image = new MagickImage(MagickColors.Fuchsia, 10, 10))
      {
        using (PixelCollection pixels = image.GetPixels())
        {
          pixels.Set(3, 3, new QuantumType[] { 0, 0, 0 });

          var valuesA = pixels.GetArea(2, 2, 4, 4);
          Assert.AreEqual(48, valuesA.Length);

          var pixelB = pixels.GetArea(new MagickGeometry(3, 3, 1, 1));
          Assert.AreEqual(3, pixelB.Length);

          var pixelA = valuesA.Skip(15).Take(3).ToArray();

          CollectionAssert.AreEqual(pixelA, pixelB);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:20,代码来源:PixelCollectionTests.cs

示例10: Test_Ping

    public void Test_Ping()
    {
      MagickImage image = new MagickImage();

      ExceptionAssert.Throws<ArgumentException>(delegate ()
      {
        image.Ping(new byte[0]);
      });

      ExceptionAssert.Throws<ArgumentNullException>(delegate ()
      {
        image.Ping((byte[])null);
      });

      ExceptionAssert.Throws<ArgumentNullException>(delegate ()
      {
        image.Ping((Stream)null);
      });

      ExceptionAssert.Throws<ArgumentNullException>(delegate ()
      {
        image.Ping((string)null);
      });

      ExceptionAssert.Throws<ArgumentException>(delegate ()
      {
        image.Ping(Files.Missing);
      });

      image.Ping(Files.FujiFilmFinePixS1ProJPG);
      Test_Ping(image);
      Assert.AreEqual(600, image.Width);
      Assert.AreEqual(400, image.Height);

      image.Ping(new FileInfo(Files.FujiFilmFinePixS1ProJPG));
      Test_Ping(image);
      Assert.AreEqual(600, image.Width);
      Assert.AreEqual(400, image.Height);

      image.Ping(File.ReadAllBytes(Files.FujiFilmFinePixS1ProJPG));
      Test_Ping(image);
      Assert.AreEqual(600, image.Width);
      Assert.AreEqual(400, image.Height);

      image.Read(Files.SnakewarePNG);
      Assert.AreEqual(286, image.Width);
      Assert.AreEqual(67, image.Height);
      using (PixelCollection pixels = image.GetPixels())
      {
        Assert.AreEqual(38324, pixels.ToArray().Length);
      }

      image.Dispose();
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:54,代码来源:MagickImageTests.cs

示例11: Test_ToByteArray

    public void Test_ToByteArray()
    {
      using (MagickImage image = new MagickImage(MagickColors.Red, 10, 10))
      {
        using (PixelCollection pixels = image.GetPixels())
        {
          var bytes = pixels.ToByteArray(0, 0, 1, 1, "BGR");
          Assert.AreEqual(3, bytes.Length);
          CollectionAssert.AreEqual(new byte[] { 0, 0, 255 }, bytes);

          bytes = pixels.ToByteArray(0, 0, 1, 1, "BG");
          Assert.AreEqual(2, bytes.Length);
          CollectionAssert.AreEqual(new byte[] { 0, 0 }, bytes);
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:16,代码来源:PixelCollectionTests.cs

示例12: Test_OptimizeTransparency

    public void Test_OptimizeTransparency()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.OptimizeTransparency();
        });

        collection.Add(new MagickImage(MagickColors.Red, 11, 11));

        MagickImage image = new MagickImage(MagickColors.Red, 11, 11);
        using (var pixels = image.GetPixels())
        {
          pixels.Set(5, 5, new QuantumType[] { 0, Quantum.Max, 0 });
        }
        collection.Add(image);
        collection.OptimizeTransparency();

        Assert.AreEqual(11, collection[1].Width);
        Assert.AreEqual(11, collection[1].Height);
        Assert.AreEqual(0, collection[1].Page.X);
        Assert.AreEqual(0, collection[1].Page.Y);
        ColorAssert.AreEqual(MagickColors.Lime, collection[1], 5, 5);
        ColorAssert.AreEqual(new MagickColor("#f000"), collection[1], 4, 4);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:27,代码来源:MagickImageCollectionTests.cs

示例13: Test_OptimizePlus

    public void Test_OptimizePlus()
    {
      using (MagickImageCollection collection = new MagickImageCollection())
      {
        ExceptionAssert.Throws<InvalidOperationException>(delegate ()
        {
          collection.OptimizePlus();
        });

        collection.Add(new MagickImage(MagickColors.Red, 11, 11));
        /* the second image will not be removed if it is a duplicate so we
           need to add an extra one. */
        collection.Add(new MagickImage(MagickColors.Red, 11, 11));
        collection.Add(new MagickImage(MagickColors.Red, 11, 11));

        MagickImage image = new MagickImage(MagickColors.Red, 11, 11);
        using (var pixels = image.GetPixels())
        {
          pixels.Set(5, 5, new QuantumType[] { 0, Quantum.Max, 0 });
        }
        collection.Add(image);
        collection.OptimizePlus();

        Assert.AreEqual(3, collection.Count);

        Assert.AreEqual(1, collection[1].Width);
        Assert.AreEqual(1, collection[1].Height);
        Assert.AreEqual(-1, collection[1].Page.X);
        Assert.AreEqual(-1, collection[1].Page.Y);
        ColorAssert.AreEqual(MagickColors.Red, collection[1], 0, 0);

        Assert.AreEqual(1, collection[2].Width);
        Assert.AreEqual(1, collection[2].Height);
        Assert.AreEqual(5, collection[2].Page.X);
        Assert.AreEqual(5, collection[2].Page.Y);
        ColorAssert.AreEqual(MagickColors.Lime, collection[2], 0, 0);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:38,代码来源:MagickImageCollectionTests.cs

示例14: Test_Image_Read

    public void Test_Image_Read()
    {
      MagickReadSettings settings = CreateSettings();

      using (MagickImage image = new MagickImage())
      {
        byte[] data = new byte[]
          {
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0xf0, 0x3f,
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0xf0, 0x3f,
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0,
          };
        image.Read(data, settings);

        Assert.AreEqual(2, image.Width);
        Assert.AreEqual(1, image.Height);

        using (PixelCollection pixels = image.GetPixels())
        {
          Pixel pixel = pixels.GetPixel(0, 0);
          Assert.AreEqual(4, pixel.Channels);
          Assert.AreEqual(0, pixel.GetChannel(0));
          Assert.AreEqual(0, pixel.GetChannel(1));
          Assert.AreEqual(0, pixel.GetChannel(2));
          Assert.AreEqual(Quantum.Max, pixel.GetChannel(3));

          pixel = pixels.GetPixel(1, 0);
          Assert.AreEqual(4, pixel.Channels);
          Assert.AreEqual(0, pixel.GetChannel(0));
          Assert.AreEqual(Quantum.Max, pixel.GetChannel(1));
          Assert.AreEqual(0, pixel.GetChannel(2));
          Assert.AreEqual(0, pixel.GetChannel(3));

          ExceptionAssert.Throws<ArgumentOutOfRangeException>(delegate ()
          {
            pixels.GetPixel(0, 1);
          });
        }
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:45,代码来源:PixelStorageSettingsTests.cs

示例15: Test_SparseColors

    public void Test_SparseColors()
    {
      MagickReadSettings settings = new MagickReadSettings();
      settings.Width = 600;
      settings.Height = 60;

      using (MagickImage image = new MagickImage("xc:", settings))
      {
        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          image.SparseColor(Channels.Red, SparseColorMethod.Barycentric, null);
        });

        List<SparseColorArg> args = new List<SparseColorArg>();

        ExceptionAssert.Throws<ArgumentException>(delegate ()
        {
          image.SparseColor(Channels.Blue, SparseColorMethod.Barycentric, args);
        });

        using (PixelCollection pixels = image.GetPixels())
        {
          ColorAssert.AreEqual(pixels.GetPixel(0, 0).ToColor(), pixels.GetPixel(599, 59).ToColor());
        }

        ExceptionAssert.Throws<ArgumentNullException>(delegate ()
        {
          args.Add(new SparseColorArg(0, 0, null));
        });

        args.Add(new SparseColorArg(0, 0, MagickColors.SkyBlue));
        args.Add(new SparseColorArg(-600, 60, MagickColors.SkyBlue));
        args.Add(new SparseColorArg(600, 60, MagickColors.Black));

        image.SparseColor(SparseColorMethod.Barycentric, args);

        using (PixelCollection pixels = image.GetPixels())
        {
          ColorAssert.AreNotEqual(pixels.GetPixel(0, 0).ToColor(), pixels.GetPixel(599, 59).ToColor());
        }

        ExceptionAssert.Throws<ArgumentException>(delegate ()
        {
          image.SparseColor(Channels.Black, SparseColorMethod.Barycentric, args);
        });
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:47,代码来源:MagickImageTests.cs


注:本文中的ImageMagick.MagickImage.GetPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。