예제 #1
0
        public static BasicSVG FillRegionList(ShapeType type, Bitmap Img, int FillWidth, int FillHeight)
        {
            Rectangle ImgRect = new Rectangle(0, 0, Img.Width, Img.Height); // generate for all objects
            BasicSVG  svg     = new BasicSVG(ImgRect);
            int       count   = 0;

            for (int currentX = 0; currentX < Img.Width; currentX += FillWidth)
            {
                for (int currentY = (count % 2 == 0) ? 0 : -FillHeight / 2; currentY < FillHeight + Img.Height; currentY += FillHeight)
                {
                    switch (type)
                    {
                    case ShapeType.square:
                        svg.addPoint(new Square(ImgRect, currentX, currentY, FillWidth, FillHeight).setAndgetAverageColorUnsafe(Img), new System.Windows.Point[]
                        {
                            new System.Windows.Point(currentX, currentY),
                            new System.Windows.Point(currentX, currentY + FillHeight),
                            new System.Windows.Point(currentX + FillWidth, currentY),
                            new System.Windows.Point(currentX + FillWidth, currentY + FillHeight)
                        });
                        break;

                    case ShapeType.triangle:
                        svg.addPoint(new LeftPointTriangle(ImgRect, currentX, currentY, FillWidth, FillHeight).getandSetAverageColor(Img), new System.Windows.Point[]
                        {
                            new System.Windows.Point(currentX + FillWidth, currentY),
                            new System.Windows.Point(currentX, currentY + (FillHeight / 2.0)),
                            new System.Windows.Point(currentX, currentY - (FillHeight / 2.0))
                        });

                        svg.addPoint(new RightPointTriangle(ImgRect, currentX, currentY + FillHeight / 2, FillWidth, FillHeight).getandSetAverageColor(Img), new System.Windows.Point[]
                        {
                            new System.Windows.Point(currentX, currentY + (FillHeight / 2.0)),
                            new System.Windows.Point(currentX + FillWidth, currentY + FillHeight),
                            new System.Windows.Point(currentX + FillWidth, currentY)
                        });
                        break;
                    }
                }
                count++;
            }
            return(svg);
        }
예제 #2
0
        private void UI_Btn_Compute_Click(object sender, RoutedEventArgs e)
        {
            string OutputFile = Path.Combine(UI_txtBox_Path.Text, UI_txtBox_FileName.Text);

            using (Bitmap bmp = new Bitmap(LoadedImg))
            {
                if (UI_RadioBtn_Svg.IsChecked == true)
                {
                    OutputExtention = ".svg";
                    OutputFile     += OutputExtention;
                    if (!UI_Btn_Compute_Click_ContinueOperations(OutputFile))
                    {
                        return;
                    }

                    BasicSVG svg = RegionFill.FillRegionList(getShapeType(), bmp, (int)UI_CustomSlider_X.Value + 1, (int)UI_CustomSlider_Y.Value + 1);
                    svg.endInit();
                    File.WriteAllText(OutputFile, svg.ToString());
                }
                else if (UI_RadioBtn_Image.IsChecked == true)
                {
                    OutputExtention = Path.GetExtension(InputFile);
                    OutputFile     += OutputExtention;
                    if (!UI_Btn_Compute_Click_ContinueOperations(OutputFile))
                    {
                        return;
                    }

                    RegionFill.FillRegionList(getShapeType(), bmp, (int)UI_CustomSlider_X.Value + 1, (int)UI_CustomSlider_Y.Value + 1);
                    bmp.Save(tempImgFile);
                    bmp.Save(OutputFile);
                }

                UI_Grid_OutputButtons.IsEnabled = true;
            }
        }