private void imageViewStripMenu_Export_Click(object sender, EventArgs e)
        {
            if (imageTreeView.SelectedNode != null)
            {
                StringBuilder builder = new StringBuilder();
                Dictionary <string, GCImage> imagePairs = (Dictionary <string, GCImage>)(imageTreeView.SelectedNode.Tag == null ? imageTreeView.SelectedNode.Parent.Tag : imageTreeView.SelectedNode.Tag);
                if (imageTreeView.SelectedNode.Nodes.Count == 0)
                {
                    switch (imagePairs[imageTreeView.SelectedNode.Text].Type)
                    {
                    case "text":
                        builder.Append("'");
                        builder.Append(imageTreeView.SelectedNode.Text);
                        builder.Append(imagePairs[imageTreeView.SelectedNode.Text].data);
                        builder.Append("'\n\r");
                        break;

                    case "bitmap":
                        builder.Append(imageTreeView.SelectedNode.Text);
                        builder.Append(" = '");
                        builder.Append(GCBase64.GetString(imagePairs[imageTreeView.SelectedNode.Text].bitmap.Width, 2));
                        builder.Append(GCBase64.GetString(imagePairs[imageTreeView.SelectedNode.Text].bitmap.Height, 2));
                        builder.Append(imagePairs[imageTreeView.SelectedNode.Text].data);
                        builder.Append(" '\n\r");
                        break;
                    }
                }
                else
                {
                    if (imagePairs[imageTreeView.SelectedNode.Nodes[0].Text].Type == "text")
                    {
                        builder.Append("'");
                        foreach (TreeNode node in imageTreeView.SelectedNode.Nodes)
                        {
                            builder.Append(node.Text);
                            builder.Append(imagePairs[node.Text].data);
                            builder.Append(" ");
                        }
                        builder.Append("'");
                    }
                    else
                    {
                        foreach (TreeNode node in imageTreeView.SelectedNode.Nodes)
                        {
                            builder.Append(node.Text);
                            builder.Append(" = '");
                            builder.Append(GCBase64.GetString(imagePairs[node.Text].bitmap.Width, 2));
                            builder.Append(GCBase64.GetString(imagePairs[node.Text].bitmap.Height, 2));
                            builder.Append(imagePairs[node.Text].data);
                            builder.Append(" '\n\r");
                        }
                    }
                }

                Clipboard.SetDataObject(builder.ToString(), true);
                MessageBox.Show("成功复制到剪贴板,字符串长度:" + builder.Length);
            }
        }
Example #2
0
        public void GetBoxs()
        {
            int minx = 64;

            Dictionary <int, List <int> > colorBoxsPairs = new Dictionary <int, List <int> >();

            Color[,] pix = new Color[bitmap.Height, bitmap.Width];

            for (int j = 0; j < bitmap.Height; j++)
            {
                for (int k = 0; k < bitmap.Width; k++)
                {
                    pix[j, k] = bitmap.GetPixel(k, j);
                }
            }

            for (int R = 0; R < bitmap.Height; R++)
            {
                for (int C = 0; C < bitmap.Width; C++)
                {
                    if (pix[R, C] != Color.Empty && pix[R, C].A != 0)
                    {
                        Color temp = pix[R, C];
                        int   r    = 0;
                        int   c    = 0;
                        while (R + r < bitmap.Height)
                        {
                            if (pix[R + r, C] != temp)
                            {
                                break;
                            }
                            r++;
                        }
                        while (C + c < bitmap.Width)
                        {
                            if (pix[R, C + c] != temp)
                            {
                                break;
                            }
                            c++;
                        }
                        int int_color = temp.R + temp.G * 256 + temp.B * 65536;

                        if (r > c)
                        {
                            for (int m = 0; m < r; m++)
                            {
                                pix[R + m, C] = Color.Empty;
                            }
                            if (!colorBoxsPairs.ContainsKey(int_color))
                            {
                                colorBoxsPairs.Add(int_color, new List <int>());
                            }
                            List <int> list = colorBoxsPairs[int_color];
                            if (Type == "text")
                            {
                                if (minx > C)
                                {
                                    minx = C;
                                }
                            }
                            list.Add(C);
                            list.Add(R);
                            list.Add(1);
                            list.Add(r);
                        }
                        else
                        {
                            for (int m = 0; m < c; m++)
                            {
                                pix[R, C + m] = Color.Empty;
                            }
                            if (!colorBoxsPairs.ContainsKey(int_color))
                            {
                                colorBoxsPairs.Add(int_color, new List <int>());
                            }
                            List <int> list = colorBoxsPairs[int_color];
                            if (Type == "text")
                            {
                                if (minx > C)
                                {
                                    minx = C;
                                }
                            }
                            list.Add(C);
                            list.Add(R);
                            list.Add(c);
                            list.Add(1);
                        }
                        boxCount++;
                    }
                }
            }

            StringBuilder builder = new StringBuilder(boxCount * 4);

            int bit;

            if (Type == "bitmap")
            {
                bit = 2;
            }
            else
            {
                bit = 1;
                foreach (var item in colorBoxsPairs.Values)
                {
                    for (int i = 0; i < item.Count; i += 4)
                    {
                        item[i] -= minx;
                    }
                }
            }

            foreach (var item in colorBoxsPairs)
            {
                if (Type == "bitmap")
                {
                    builder.Append(GCBase64.GetString(item.Key, 4));
                }
                foreach (var value in item.Value)
                {
                    builder.Append(GCBase64.GetString(value, bit));
                }
                builder.Append(" ");
            }
            builder.Remove(builder.Length - 1, 1);
            data = builder.ToString();
            Console.WriteLine(data);
        }