private MagickImage CreateImage(int? density)
    {
      MagickImage image = new MagickImage(MagickColors.Purple, 500, 500);
      DrawableFontPointSize pointSize = new DrawableFontPointSize(20);
      DrawableText text = new DrawableText(250, 250, "Magick.NET");

      if (!density.HasValue)
        image.Draw(pointSize, text);
      else
        image.Draw(pointSize, new DrawableDensity(density.Value), text);

      image.Trim();

      return image;
    }
Beispiel #2
0
 private static void ExecuteTrim(MagickImage image)
 {
   image.Trim();
 }
Beispiel #3
0
        public MagickImage Draw()
        {
            MainForm.ProgressStart("Rendering background ...");

            // Check which terrain file is used
            string texMpk = string.Format("{0}\\tex{1}.mpk", this.textureZoneDataDirectory, this.textureZoneId);
            string lodMpk = string.Format("{0}\\lod{1}.mpk", this.textureZoneDataDirectory, this.textureZoneId);

            // Get the tile dimension
            double tileWidth = 512.0;
            string tileTemplate = "";

            MPAK mpak = new MPAK();
            if (File.Exists(texMpk))
            {
                mpak.Load(texMpk);

                if (mpak.Files.Where(f => f.Name.ToLower() == "tex00-00.dds").Count() > 0)
                {
                    tileTemplate += "tex0{0}-0{1}.dds";
                    tileWidth = 512.0;
                }
            }

            if (string.IsNullOrEmpty(tileTemplate))
            {
                mpak.Load(lodMpk);

                if (mpak.Files.Where(f => f.Name.ToLower() == "lod00-00.dds").Count() > 0)
                {
                    tileTemplate += "lod0{0}-0{1}.dds";
                    tileWidth = 256.0;
                }
            }

            if (string.IsNullOrEmpty(tileTemplate))
            {
                MainForm.Log(string.Format("Zone {0}: No background textures found!", zoneConfiguration.ZoneId), MainForm.LogLevel.error);
                return null;
            }

            // original size
            double orginalWidth = tileWidth * 8;
            double resizeFactor = (double)zoneConfiguration.TargetMapSize / (double)orginalWidth; // 0 - 1

            MagickImage map = new MagickImage(Color.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize);

            int lastWidth = 0;
            int x = 0;
            for (int col = 0; col <= 7; col++)
            {
                int y = 0;
                for (int row = 0; row <= 7; row++)
                {
                    string filename = string.Format(tileTemplate, col, row);

                    using (MagickImage mapTile = new MagickImage(mpak.GetFile(filename).Data))
                    {
                        int newSize = Convert.ToInt32(mapTile.Width * resizeFactor);
                        mapTile.Resize(newSize, newSize);

                        map.Composite(mapTile, x, y, CompositeOperator.SrcOver);

                        // Calculate new y
                        y += mapTile.Height;
                        lastWidth = mapTile.Height;
                    }
                }

                x += lastWidth;

                int percent = 100 * col / 8;
                MainForm.ProgressUpdate(percent);
            }

            MainForm.ProgressStartMarquee("Merging ...");

            // Remove rounding fails
            map.Trim();

            // Flip if set
            if (this.flipX) map.Flop();
            if (this.flipY) map.Flip();

            // Sharpen (tested a lot, seems to be the best values)
            map.Sharpen(4, 3);

            MainForm.ProgressReset();

            return map;
        }
    public void Test_Trim()
    {
      using (MagickImage image = new MagickImage("xc:fuchsia", 50, 50))
      {
        ColorAssert.AreEqual(MagickColors.Fuchsia, image, 0, 0);
        ColorAssert.AreEqual(MagickColors.Fuchsia, image, 49, 49);

        image.Extent(100, 60, Gravity.Center, MagickColors.Gold);

        Assert.AreEqual(100, image.Width);
        Assert.AreEqual(60, image.Height);
        ColorAssert.AreEqual(MagickColors.Gold, image, 0, 0);
        ColorAssert.AreEqual(MagickColors.Fuchsia, image, 50, 30);

        image.Trim();

        Assert.AreEqual(50, image.Width);
        Assert.AreEqual(50, image.Height);
        ColorAssert.AreEqual(MagickColors.Fuchsia, image, 0, 0);
        ColorAssert.AreEqual(MagickColors.Fuchsia, image, 49, 49);
      }
    }