Ejemplo n.º 1
0
        public static AppendContentBuilder FromString(string str)
        {
            var match = reg.Match(str);

            if (!match.Success)
            {
                return(null);
            }

            var builder = new AppendContentBuilder();

            if (match.Groups.Count == 2)
            {
                var captureCollection = match.Groups[1].Captures;
                for (int i = 0; i < captureCollection.Count; i++)
                {
                    var itemStr = captureCollection[i].Value;
                    var items   = itemStr.Substring(1, itemStr.Length - 2).Split(new char[] { ',' });
                    var content = new AppendContent
                    {
                        X     = int.Parse(items[0]),
                        Y     = int.Parse(items[1]),
                        Color = int.Parse(items[2])
                    };
                    builder.Contents.Add(content);
                }
            }
            return(builder);
        }
Ejemplo n.º 2
0
        public void modify(FileInfo file)
        {
            Bitmap               bitmap        = null;
            AppendContent        appendContent = null;
            AppendContentBuilder builder       = AppendContentBuilder.ParseFile(file) ?? new AppendContentBuilder();

            try
            {
                using (var fs = file.OpenRead())
                {
                    bitmap = new Bitmap(fs);
                }

                Random random = new Random((int)DateTime.Now.Ticks);
                for (int i = 0; i < 2048 * 2048; i++)
                {
                    var x     = random.Next(bitmap.Width);
                    var y     = random.Next(bitmap.Height);
                    var pixel = bitmap.GetPixel(x, y);
                    if (pixel.ToArgb() != Color.Transparent.ToArgb())
                    {
                        if (pixel.A > 125)
                        {
                            bitmap.SetPixel(x, y, Color.FromArgb(pixel.A - random.Next(1, 3), pixel));
                        }
                        else
                        {
                            bitmap.SetPixel(x, y, Color.FromArgb(pixel.A + random.Next(1, 3), pixel));
                        }
                        appendContent = new AppendContent {
                            X = x, Y = y, Color = pixel.ToArgb()
                        };
                        break;
                    }
                }

                bitmap.Save(file.FullName);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }
            if (appendContent != null)
            {
                builder.Contents.Add(appendContent);
                AppendContentBuilder.AddContent2File(file.FullName, builder.Contents);
            }

            //var png = new Png(file);
            //png.AddInternationalText("comment", "hello " + DateTime.Now.Ticks);
            //png.SaveFile();
        }