private Image GetTexture(SColor color, Dictionary <SColor, Image> cache, IEnumerable <MinecraftBlock> blocks)
        {
            if (cache.ContainsKey(color))
            {
                return(cache[color]);
            }

            var block = blocks.First(x => SColor
                                     .FromArgb(x.MapColor.A, x.MapColor.R, x.MapColor.G, x.MapColor.B)
                                     .Equals(color));

            var texture = _storage.GetImage(block.TexturePath);

            cache[color] = texture;

            return(texture);
        }
示例#2
0
        public async Task <IEnumerable <ColorMentionsCount> > CountColorsMentionsFromImageAsync(string imagePath)
        {
            var image = _storage.GetImage(imagePath);

            var mentions = _counter.CountColorsMentions(image);

            var colors = await _repository.GetAsync <Color>();

            return(colors.Join(mentions,
                               x => System.Drawing.Color.FromArgb(x.A, x.R, x.G, x.B),
                               x => x.Key,
                               (c, m) => new ColorMentionsCount
            {
                Id = c.Id,
                A = c.A,
                B = c.B,
                R = c.R,
                G = c.G,
                MentionsCount = m.Value
            }));
        }
示例#3
0
        public async Task <PixelartCreationResultModel> CreateAsync(PixelartCreateModel model)
        {
            var image = _storage.GetImage(model.SourcePath);

            var ids    = model.AvailibleColorsIds;
            var colors = await _repository.GetAsync <Color>(x => ids.Contains(x.Id));

            var options = new PixelizingOptions
            {
                AvailibleColors = colors.Select(x => System.Drawing.Color.FromArgb(x.A, x.R, x.G, x.B)),
                Size            = model.Size * (int)model.Unit
            };

            var result = _pixelartGenerator.CreatePixelart(image, options);

            var path = _storage.SaveImage(result);

            return(new PixelartCreationResultModel {
                ResultPath = path
            });
        }