Encapsulation of the DrawableCompositeImage object.
Inheritance: IDrawableText
Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
        private void DebugMaps()
        {
            MainForm.Log("Drawing debug bound images ...", MainForm.LogLevel.warning);
            MainForm.ProgressStartMarquee("Debug bound images ...");

            DirectoryInfo debugDir = new DirectoryInfo(string.Format("{0}\\debug\\bound\\{1}", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId));
            if (!debugDir.Exists) debugDir.Create();
            debugDir.GetFiles().ToList().ForEach(f => f.Delete());

            int boundIndex = 0;
            foreach (List<PointF> allCoords in m_bounds)
            {
                using (MagickImage bound = new MagickImage(MagickColor.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
                {
                    List<Coordinate> coords = allCoords.Select(c => new Coordinate(zoneConfiguration.ZoneCoordinateToMapCoordinate(c.X), zoneConfiguration.ZoneCoordinateToMapCoordinate(c.Y))).ToList();

                    DrawablePolygon poly = new DrawablePolygon(coords);
                    bound.FillColor = new MagickColor(0, 0, 0, 256 * 128);
                    bound.Draw(poly);

                    // Print Text
                    for (int i = 0; i < coords.Count; i++)
                    {
                        double x, y;

                        if (coords[i].X > zoneConfiguration.TargetMapSize / 2) x = coords[i].X - 15;
                        else x = coords[i].X + 1;

                        if (coords[i].Y < zoneConfiguration.TargetMapSize / 2) y = coords[i].Y + 15;
                        else y = coords[i].Y - 1;

                        bound.FontPointsize = 10.0;
                        bound.FillColor = Color.Black;
                        DrawableText text = new DrawableText(x, y, string.Format("{0} ({1}/{2})", i, zoneConfiguration.MapCoordinateToZoneCoordinate(coords[i].X), zoneConfiguration.MapCoordinateToZoneCoordinate(coords[i].Y)));
                        bound.Draw(text);

                        using (WritablePixelCollection pixels = bound.GetWritablePixels())
                        {
                            int x2, y2;
                            if (coords[i].X == zoneConfiguration.TargetMapSize) x2 = zoneConfiguration.TargetMapSize - 1;
                            else x2 = (int)coords[i].X;
                            if (coords[i].Y == zoneConfiguration.TargetMapSize) y2 = zoneConfiguration.TargetMapSize - 1;
                            else y2 = (int)coords[i].Y;

                            pixels.Set(x2, y2, new ushort[] { 0, 0, 65535, 0 });
                        }
                    }

                    //bound.Quality = 100;
                    bound.Write(string.Format("{0}\\bound_{1}.png", debugDir.FullName, boundIndex));

                    boundIndex++;
                }
            }

            MainForm.ProgressReset();
        }
Ejemplo n.º 3
0
        private void DebugRiver(int index, WaterConfiguration river, List<Coordinate> riverCoordinates)
        {
            string debugFilename = string.Format("{0}\\debug\\rivers\\{1}_{2}_{3}.jpg", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId, index, river.Name);

            if (index == 0)
            {
                DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(debugFilename));
                if (di.Exists) di.EnumerateFiles().ToList().ForEach(f => f.Delete());
                else di.Create();
            }

            using (MagickImage debugRiver = new MagickImage(MagickColor.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize))
            {
                debugRiver.BackgroundColor = Color.White;
                debugRiver.FillColor = new MagickColor(0, 0, ushort.MaxValue, 256 * 128);

                double resizeFactor = zoneConfiguration.TargetMapSize / zoneConfiguration.Heightmap.Heightmap.Width;

                DrawablePolygon poly = new DrawablePolygon(riverCoordinates);
                debugRiver.Draw(poly);

                List<Coordinate> orginalCoords = river.GetCoordinates();
                for (int i = 0; i < riverCoordinates.Count(); i++)
                {
                    double x, y;

                    if (riverCoordinates[i].X > zoneConfiguration.TargetMapSize / 2) x = riverCoordinates[i].X - 15;
                    else x = riverCoordinates[i].X + 1;

                    if (riverCoordinates[i].Y < zoneConfiguration.TargetMapSize / 2) y = riverCoordinates[i].Y + 15;
                    else y = riverCoordinates[i].Y - 1;

                    debugRiver.FontPointsize = 14.0;
                    debugRiver.FillColor = Color.Black;
                    DrawableText text = new DrawableText(x, y, string.Format("{0} ({1}/{2})", i, orginalCoords[i].X, orginalCoords[i].Y));
                    debugRiver.Draw(text);
                }

                debugRiver.Quality = 100;
                debugRiver.Write(debugFilename);
            }
        }