Exemple #1
0
        public static IEnumerable <KeyValuePair <Point, Color> > GetDistributionColor(this IEnumerable <KeyValuePair <Point, Color> > points, IPixelDrawable d, int width)
        {
            Dictionary <Point, Color> result = new Dictionary <Point, Color>();

            foreach (var obj in points)
            {
                if (obj.Key.X >= 0 && obj.Key.X <= d.PixelSize.Width && obj.Key.Y >= 0 && obj.Key.Y <= d.PixelSize.Height)
                {
                    int l = (int)Math.Ceiling((width - 1) / 2.0);
                    for (int i = obj.Key.X - l; i <= obj.Key.X + l; ++i)
                    {
                        for (int j = obj.Key.Y - l; j <= obj.Key.Y + l; ++j)
                        {
                            var p     = new Point(i, j);
                            var old_c = d.ReadPixel(p);
                            if (result.ContainsKey(p))
                            {
                                old_c = result[p];
                            }

                            result[p] = CozyPixelHelper.Blend(obj.Value, old_c, CozyPixelHelper.LinearWeight(obj.Key.Length(p), width));;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        protected override bool OnEnd(Point p)
        {
            base.OnEnd(p);

            if (Target != null && ColorHolder != null && Target.IsReady)
            {
                var points  = CozyPixelHelper.GetAllPoint(DrawPoints, ColorHolder.CurrColor);
                var command = new DrawPixelCommand()
                {
                    Points = points.GetDistributionColor(Target, Width),
                    Target = Target,
                };
                CommandManager.Instance.Do(command);

                Target.UpdateDrawable();
                return(true);
            }
            return(false);
        }
Exemple #3
0
        public bool TryAddImage(string path)
        {
            var img = CozyPixelHelper.ReadBitmapFromFile(path);

            if (img.Width > 128 || img.Height > 128)
            {
                return(false);
            }

            int i = PathList.Count;

            PathList.Add(path);
            ImgList.Images.Add(img);

            var filename = Path.GetFileNameWithoutExtension(path);

            Items.Add(filename.Substring(0, (filename.Length < MaxNameLength ? filename.Length : MaxNameLength)), i);
            Items[i].ImageIndex  = i;
            Items[i].ToolTipText = filename;

            return(true);
        }