Пример #1
0
        public static System.IO.Stream WriteTextToImage(string text)
        {
            using (SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> .Load("Assets/share-bg.png"))
            {
                SixLabors.Fonts.FontCollection fontCollection = new SixLabors.Fonts.FontCollection();
                SixLabors.Fonts.Font           regularFont    = fontCollection.Install("Assets/TitilliumWeb-SemiBold.ttf").CreateFont(24, SixLabors.Fonts.FontStyle.Regular);
                SixLabors.Fonts.Font           italicFont     = fontCollection.Install("Assets/TitilliumWeb-BoldItalic.ttf").CreateFont(24, SixLabors.Fonts.FontStyle.Italic);

                image.Mutate(x => x.DrawText(text, regularFont, SixLabors.ImageSharp.Color.White, new SixLabors.ImageSharp.PointF(100, 100)));

                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                image.Save(stream, new SixLabors.ImageSharp.Formats.Png.PngEncoder());
                stream.Position = 0;
                return(stream);
            }
        }
Пример #2
0
        static void PrintSystemFonts()
        {
            var collection = new SixLabors.Fonts.FontCollection();

            System.Collections.Generic.IEnumerable <FontFamily> families = SystemFonts.Collection.Families;
            IOrderedEnumerable <FontFamily> orderd = families.OrderBy(x => x.Name);
            int len = families.Max(x => x.Name.Length);

            foreach (FontFamily f in orderd)
            {
                Console.Write(f.Name.PadRight(len));
                Console.Write('\t');
                Console.Write(string.Join(",", f.AvailableStyles.OrderBy(x => x).Select(x => x.ToString())));
                Console.WriteLine();
            }
        }
Пример #3
0
        /// <summary>
        /// Draw square boxes around each area to approximate how they would behave in an offline app
        /// </summary>
        /// <param name="info">the image information for drawing</param>
        /// <param name="items">the elements to draw.</param>
        /// <returns>byte array of the generated .png tile image</returns>
        public byte[] DrawOfflineEstimatedAreas(ImageStats info, List <DbTables.Place> items)
        {
            //TODO retest this.
            var image   = new Image <Rgba32>(info.imageSizeX, info.imageSizeY);
            var bgColor = Rgba32.ParseHex("00000000");

            image.Mutate(x => x.Fill(bgColor));
            var fillColor   = Rgba32.ParseHex("000000");
            var strokeColor = Rgba32.ParseHex("000000");

            var placeInfo = Standalone.Standalone.GetPlaceInfo(items.Where(i =>
                                                                           i.IsGameElement
                                                                           ).ToList());

            //this is for rectangles.
            foreach (var pi in placeInfo)
            {
                var rect = PlaceInfoToRect(pi, info);
                fillColor = Rgba32.ParseHex(TagParser.PickStaticColorForArea(pi.Name));
                image.Mutate(x => x.Fill(fillColor, rect));
                image.Mutate(x => x.Draw(strokeColor, 3, rect));
            }

            image.Mutate(x => x.Flip(FlipMode.Vertical));;  //inverts the inverted image again!
            foreach (var pi in placeInfo)
            {
                //NOTE: would be better to load fonts once and share that for the app's lifetime.
                var fonts  = new SixLabors.Fonts.FontCollection();
                var family = fonts.Add("fontHere.ttf");
                var font   = family.CreateFont(12, FontStyle.Regular);
                var rect   = PlaceInfoToRect(pi, info);
                image.Mutate(x => x.DrawText(pi.Name, font, strokeColor, new PointF((float)(pi.lonCenter * info.pixelsPerDegreeX), (float)(pi.latCenter * info.pixelsPerDegreeY))));
            }

            image.Mutate(x => x.Flip(FlipMode.Vertical)); //Plus codes are south-to-north, so invert the image to make it correct.
            var ms = new MemoryStream();

            image.SaveAsPng(ms);
            return(ms.ToArray());
        }
Пример #4
0
        private Visualizer()
        {
            var fontDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);

            var dir       = new DirectoryInfo(fontDir);
            var arialFile = dir.EnumerateFiles("arial.ttf").First();

            var fonts = new FontCollection();
            var arial = fonts.Install(arialFile.FullName);

            shapeGraphicsOptions = new ShapeGraphicsOptions();
            foregroundBrush      = new SolidBrush(Color.Black);
            edgeThickness        = 1;
            font = arial.CreateFont(12);

            nodeHeight       = 24;
            nodeSegmentWidth = 50;
            layerHeight      = nodeHeight * 3;

            pageMargin = 12;

            drawables = new List <Drawable>();
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FontFamily"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="collection">The collection.</param>
 /// <param name="culture">The culture the family was extracted against</param>
 internal FontFamily(string name, FontCollection collection, CultureInfo culture)
 {
     this.collection = collection ?? throw new ArgumentNullException(nameof(collection));
     this.Name       = name;
     this.Culture    = culture;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FontFamily"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="collection">The collection.</param>
 internal FontFamily(string name, FontCollection collection)
 {
     this.collection = collection;
     this.Name       = name;
 }