コード例 #1
0
        public void ApplyFilter(MainWindow mainWindow)
        {
            if (mainWindow.imageHandler != null)
            {
                List <byte> functionMapper = new List <byte>();
                for (int i = 0; i < lines.Count; i++)
                {
                    Line line = lines.ElementAt(i);
                    int  x0   = (int)line.X1;
                    int  y0   = 255 - (int)line.Y1;

                    int x1 = (int)line.X2;
                    int y1 = 255 - (int)line.Y2;

                    int length = x1;
                    if (i == lines.Count - 1)
                    {
                        length++;
                    }

                    for (int x = x0; x < length; x++)
                    {
                        double yDiff = y1 - y0;
                        double xDiff = x1 - x0;
                        int    y;
                        if (xDiff < 1)
                        {
                            y = y0;
                        }
                        else
                        {
                            double m = yDiff / xDiff;

                            double diff = (x - x0);
                            double d_y  = y0 + diff * m;
                            y = (int)d_y;
                        }
                        functionMapper.Add((byte)y);
                    }
                }

                CustomFilter filter = new CustomFilter(functionMapper);

                mainWindow.imageHandler.ApplyFilter(image => filter.ApplyFilter(image));

                mainWindow.filteredImage.Source = BitmapLoader.loadBitmap(mainWindow.imageHandler.getFiltered());
            }
        }