コード例 #1
0
        public static void DrawToGraphics(ref Image i, Beads b, bool original, bool drawgrid, Color? TransparentColourOverload = null)
        {
            const int pixelsize = 10;
            int w = b.width * pixelsize;
            int h = b.height * pixelsize;
            int cx = 0;
            int cy = 0;

            Brush brush = new SolidBrush(Color.White);
            i = new Bitmap(w, h);
            Graphics graphics = Graphics.FromImage(i);

            //clear
            graphics.FillRectangle(brush, 0, 0, w, h);
            b.Grid = new List<Tuple<Tuple<int, int>, Rectangle>>();
            //draw imagae
            for (int y = 0; y < b.height; y++)
            {
                for (int x = 0; x < b.width; x++)
                {
                    var c = b.GetPixelColour(x, y, original);
                    if (TransparentColourOverload != null && c.Equals(Color.Transparent))
                        c = (Color)TransparentColourOverload;
                    brush = new SolidBrush(c);

                    var r = new Rectangle(cx * pixelsize, cy * pixelsize, pixelsize, pixelsize);
                    b.Grid.Add(new Tuple<Tuple<int, int>, Rectangle>(new Tuple<int, int>(x, y), r));

                    graphics.FillRectangle(brush, r);

                    if ((x + 1) == b.width)
                    {
                        cx = 0;
                        cy++;
                    }
                    else
                    {
                        cx++;
                    }
                }
            }

            //overlay
            if (drawgrid)
            {
                var pen = new Pen(Color.White);

                for (int x = 0; x < b.width; x++)
                {
                    graphics.DrawLine(pen, x * pixelsize, 0, x * pixelsize, h);
                }

                for (int y = 0; y < b.height; y++)
                {
                    graphics.DrawLine(pen, 0, y * pixelsize, w, y * pixelsize);
                }
            }
        }
コード例 #2
0
        public static void DrawBeads(Control p, Beads b, bool orig, bool drawgrid)
        {
            if (b == null)
                return;

            b.Grid = new List<Tuple<Tuple<int, int>, Rectangle>>();

            Image i = p.BackgroundImage;
            DrawToGraphics(ref i, b, orig, drawgrid, p.BackColor);
            p.BackgroundImage = i;
        }
コード例 #3
0
ファイル: Beads.cs プロジェクト: andreigec/BeadSprite-Pro
        public static Beads Create(String fileName, bool ignorewhiteedge)
        {
            var cm = BitmapExtras.LoadFileToColourMatrix(fileName);
            if (cm == null)
                return null;

            var b = new Beads();
            b.height = cm.Count();
            b.width = cm[0].Count();
            b.OriginalColours = cm;
            b.BeadColours = MatrixOps.CreateMatrix<Color>(b.width, b.height);
            MatrixOps.SetAll(b.BeadColours, Color.Transparent);

            if (ignorewhiteedge)
                ClearEdges(b);

            return b;
        }
コード例 #4
0
        public static void ChangePalette(Beads b)
        {
            if (Beads.SelectedBeadColours == null)
                Beads.SelectedBeadColours = new List<Color>();

            var l = new List<SelectItemFromListBox.SelectItem>();
            foreach (var f in Beads.AllBeadColours)
            {
                var si = new SelectItemFromListBox.SelectItem(f.Key, Beads.SelectedBeadColours.Contains(f.Value));
                l.Add(si);
            }
            var res = SelectPalette.ShowDialog("Select the beads you wish to use", "Bead Palette Editor", l);
            if (res == null)
                return;

            Beads.SelectedBeadColours = new List<Color>();
            foreach (var s in res)
            {
                Beads.SelectedBeadColours.Add(Beads.AllBeadColours[s]);
            }
            b.UpdatePalette();
        }
コード例 #5
0
ファイル: Beads.cs プロジェクト: andreigec/BeadSprite-Pro
        public static int GetUniqueCount(Beads b, bool original)
        {
            var seen = new List<Color>();
            var l = new object();

            Parallel.For(0, b.height, (y) =>
            {
                for (int x = 0; x < b.width; x++)
                {
                    var c = b.GetPixelColour(x, y, original);

                    if (seen.Contains(c) == false)
                    {
                        lock (l)
                        {
                            seen.Add(c);
                        }
                    }
                }
            });
            return seen.Count;
        }
コード例 #6
0
        public static void UpdateMousePos(Beads LoadedBeads, Panel p, ToolStripStatusLabel newts, ToolStripStatusLabel oldts, int x, int y)
        {
            if (LoadedBeads == null)
                return;

            var pos = GetGridPos(x, y, p, LoadedBeads);
            if (pos == null)
            {
                newts.Text = "";
                newts.BackColor = Color.Transparent;
                newts.ForeColor = Color.Black;

                oldts.Text = "";
                oldts.BackColor = Color.Transparent;
                oldts.ForeColor = Color.Black;
            }
            else
            {
                SetColourText(LoadedBeads, newts, false, pos.Item1, pos.Item2);
                SetColourText(LoadedBeads, oldts, true, pos.Item1, pos.Item2);
            }
        }
コード例 #7
0
        public static void SetColourText(Beads b, ToolStripStatusLabel ts, bool orig, int x, int y)
        {
            var c = b.GetPixelColour(x, y, orig);

            ts.Text = GetColourDescription(c, orig);
            ts.BackColor = c;
            ts.ForeColor = ColorExtras.GetNegativeColour(c);
        }
コード例 #8
0
        public static void SaveCustomImageToFile(Beads beads, String filename, bool drawgrid)
        {
            var b = new Bitmap(beads.width, beads.height);
            var i = (Image)b;

            DrawToGraphics(ref i, beads, false, drawgrid);

            i.Save(filename, ImageFormat.Png);
        }
コード例 #9
0
        public static Tuple<int, int> GetGridPos(int x, int y, Panel p, Beads b)
        {
            if (p.BackgroundImageLayout == ImageLayout.None)
                return new Tuple<int, int>(x, y);

            if (p.BackgroundImageLayout == ImageLayout.Stretch)
            {
                //get pixel size
                var px = (float)p.Width / b.width;
                var py = (float)p.Height / b.height;
                var x1 = (int)Math.Floor(x / px);
                var y1 = (int)Math.Floor(y / py);
                return new Tuple<int, int>(x1, y1);
            }
            return new Tuple<int, int>(0, 0);
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: andreigec/BeadSprite-Pro
        private void loadImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();
            ofd.Title = "Select Image file to import";
            ofd.InitialDirectory = DirectoryExtras.GetExePath();
            var res = ofd.ShowDialog();
            if (res != DialogResult.OK)
                return;

            LoadedBeads = Beads.Create(ofd.FileName, ignoreWhiteBeadsFromOutsideToolStripMenuItem.Checked);
            RedrawBeads();
        }
コード例 #11
0
ファイル: Beads.cs プロジェクト: andreigec/BeadSprite-Pro
 public Beads Clone()
 {
     var b = new Beads();
     b.width = width;
     b.height = height;
     b.OriginalColours = MatrixOps.CloneMatrix(OriginalColours, width, height);
     b.BeadColours = MatrixOps.CloneMatrix(BeadColours, width, height);
     return b;
 }
コード例 #12
0
ファイル: Beads.cs プロジェクト: andreigec/BeadSprite-Pro
 private static void ClearEdges(Beads b, bool original = true)
 {
     if (original)
         MatrixOps.Replace(ref b.OriginalColours, Color.White, Color.Transparent, ColorExtras.Equals);
     else
         MatrixOps.Replace(ref b.BeadColours, Color.White, Color.Transparent, ColorExtras.Equals);
 }
コード例 #13
0
ファイル: Stats.cs プロジェクト: andreigec/BeadSprite-Pro
 public Stats(Beads b)
 {
     InitializeComponent();
     this.b = b;
 }