Пример #1
0
        public Image GetThumb()
        {
            if (ImageIn == null)
            {
                throw new Exception("Image to work with has not been defined");
            }

            return(((Image)ImageIn.Clone()).GetThumbnailImage(200, ((200 * ImageIn.Height) / ImageIn.Width), null, IntPtr.Zero));
        }
Пример #2
0
        public void Resize(Size newSize)
        {
            ImageOut = ((Image)ImageIn.Clone()).GetThumbnailImage(ImageSize.Width, ImageSize.Height, null, IntPtr.Zero);

            // Rectangle compressionRectangle = new Rectangle(0, 0,ImageSize.Width, ImageSize.Height);
            // Graphics g = Graphics.FromImage(ImageOut);

            // g.DrawImage(ImageOut, ImageSize.Width, ImageSize.Height);
            // g.Dispose();
        }
Пример #3
0
        public override void Run()
        {
            switch (MirrorType)
            {
            case EnumMirrorType.MirrorX:
                HOperatorSet.MirrorImage(ImageIn, out imageOut, "row");
                ImageIn.Dispose();
                break;

            case EnumMirrorType.MirrorY:
                HOperatorSet.MirrorImage(ImageIn, out imageOut, "column");
                ImageIn.Dispose();
                break;

            default:
                break;
            }
        }
Пример #4
0
 public override void Run()
 {
     HOperatorSet.RotateImage(ImageIn, out imageOut, (double)Angle % 360, "constant");
     ImageIn.Dispose();
 }
Пример #5
0
        public async Task <byte[]> CreateImg()
        {
            //переменные для расчета центар входящего изображения
            int ind_left  = 100000;
            int ind_right = -1;
            int ind_top   = -1;
            int ind_bot   = -1;

            //создание зеленого изображения участка
            ImageOut = ImageIn.Convert <Bgr, byte>().ThresholdBinary(new Bgr(0, 0, 0), new Bgr(120, 255, 0));
            //создание выходных изображений(чб и цветное)
            BigImg = new Image <Gray, byte>((ImageIn.Width + (int)((border / scale) * 4)), (ImageIn.Height + (int)((border / scale) * 4)));
            Image <Bgr, byte> BigImg_Color = new Image <Bgr, byte>((ImageIn.Width + (int)((border / scale) * 4)), (ImageIn.Height + (int)((border / scale) * 4)));

            //расчет центральной точки
            #region Верхний индекс
            for (int i = 0; i < ImageOut.Height; i++)
            {
                for (int j = 0; j < ImageOut.Width; j++)
                {
                    if (ImageOut.Data[i, j, 1] != 0)
                    {
                        ind_top = i;
                        break;
                    }
                }
                if (ind_top == i)
                {
                    break;
                }
            }
            #endregion
            #region Нижний индекс
            for (int i = 0; i < ImageOut.Height; i++)
            {
                for (int j = 0; j < ImageOut.Width; j++)
                {
                    if (ImageOut.Data[i, j, 1] != 0)
                    {
                        if (ind_bot <= i)
                        {
                            ind_bot = i;
                        }
                    }
                }
            }
            #endregion
            #region Левый индекс
            for (int i = 0; i < ImageOut.Height; i++)
            {
                for (int j = 0; j < ImageOut.Width; j++)
                {
                    if (ImageOut.Data[i, j, 1] != 0)
                    {
                        if (ind_left > j)
                        {
                            ind_left = j;
                        }
                    }
                }
            }
            #endregion
            #region Правый индекс
            for (int i = 0; i < ImageOut.Height; i++)
            {
                for (int j = 0; j < ImageOut.Width; j++)
                {
                    if (ImageOut.Data[i, j, 1] != 0)
                    {
                        if (ind_right < j)
                        {
                            ind_right = j;
                        }
                    }
                }
            }
            #endregion

            System.Drawing.Point center = new System.Drawing.Point(ind_left + (ind_right - ind_left) / 2, ind_top + (ind_bot - ind_top) / 2);
            //совмещение входящего изображения и выходного ЧБ
            BigImg = SummImg(BigImg, ImageIn);
            //отрисовка границ СЗЗ
            BigImg = DrawBorder(BigImg);
            //рисунок границ СЗЗ совмещается с выходныс изображением (цветное)
            BigImg_Color     = SummImg(BigImg_Color, BigImg);
            _ImageWithBorder = BigImg_Color;

            //Image<> to Bitmapsource
            ImageOutBitMap = ToBitmapSource(BigImg_Color);

            //Bitmapsource to Bitmap
            Bitmap result_img = GetBitmap(ImageOutBitMap);
            //Прозрачность
            var color = System.Drawing.Color.Black;
            result_img.MakeTransparent(color);
            // result_img.Save("result.png");
            //WorkWithCad();
            ImageConverter converter = new ImageConverter();
            byte[]         res_img   = (byte[])converter.ConvertTo(result_img, typeof(byte[]));
            return(res_img);
        }
Пример #6
0
        private Image <Gray, byte> MoveBorderToPlace()
        {
            Image <Gray, byte> ImageInGray = ImageIn.Convert <Gray, byte>();
            Image <Gray, byte> ImageBorder = _ImageWithBorder.Convert <Gray, byte>();
            int ind_left  = 100000;
            int ind_right = -1;
            int ind_top   = -1;
            int ind_bot   = -1;

            #region Верхний индекс
            for (int i = 0; i < ImageInGray.Height; i++)
            {
                for (int j = 0; j < ImageInGray.Width; j++)
                {
                    if (ImageInGray.Data[i, j, 0] != 0)
                    {
                        ind_top = i;
                        break;
                    }
                }
                if (ind_top == i)
                {
                    break;
                }
            }
            #endregion
            #region Нижний индекс
            for (int i = 0; i < ImageInGray.Height; i++)
            {
                for (int j = 0; j < ImageInGray.Width; j++)
                {
                    if (ImageInGray.Data[i, j, 0] != 0)
                    {
                        if (ind_bot <= i)
                        {
                            ind_bot = i;
                        }
                    }
                }
            }
            #endregion
            #region Левый индекс
            for (int i = 0; i < ImageInGray.Height; i++)
            {
                for (int j = 0; j < ImageInGray.Width; j++)
                {
                    if (ImageInGray.Data[i, j, 0] != 0)
                    {
                        if (ind_left > j)
                        {
                            ind_left = j;
                        }
                    }
                }
            }
            #endregion
            #region Правый индекс
            for (int i = 0; i < ImageInGray.Height; i++)
            {
                for (int j = 0; j < ImageInGray.Width; j++)
                {
                    if (ImageInGray.Data[i, j, 0] != 0)
                    {
                        if (ind_right < j)
                        {
                            ind_right = j;
                        }
                    }
                }
            }
            #endregion

            System.Drawing.Point centerImageIn     = new System.Drawing.Point(ind_left + (ind_right - ind_left) / 2, ind_top + (ind_bot - ind_top) / 2);
            System.Drawing.Point centerImageBorder = new System.Drawing.Point(_ImageWithBorder.Width / 2, _ImageWithBorder.Height / 2);
            System.Drawing.Point vector            = new System.Drawing.Point(Math.Max(centerImageIn.X, centerImageBorder.X) - Math.Min(centerImageIn.X, centerImageBorder.X), Math.Max(centerImageIn.Y, centerImageBorder.Y) - Math.Min(centerImageIn.Y, centerImageBorder.Y));
            //все точки на границе СЗЗ

            List <DatePoint> pointsPlace = new List <DatePoint>();
            //Границы
            for (int i = 0; i < ImageBorder.Height; i++)
            {
                for (int j = 0; j < ImageBorder.Width; j++)
                {
                    if (ImageBorder.Data[i, j, 0] != 0 && (ImageBorder.Data[i + 1, j, 0] == 0 || ImageBorder.Data[i - 1, j, 0] == 0 || ImageBorder.Data[i, j + 1, 0] == 0 || ImageBorder.Data[i, j - 1, 0] == 0))
                    {
                        ListBorderPonts.Add(new DatePoint(j, i, 0));
                    }
                }
            }
            //Белый участок
            for (int i = 0; i < ImageInGray.Height; i++)
            {
                for (int j = 0; j < ImageInGray.Width; j++)
                {
                    if (ImageInGray.Data[i, j, 0] != 0)
                    {
                        pointsPlace.Add(new DatePoint(j, i, 0));
                    }
                }
            }
            //перенос в записимости от взаиморасположения центров
            List <DatePoint> _list_border_points = new List <DatePoint>();
            foreach (var item in ListBorderPonts)
            {
                _list_border_points.Add(item);
            }
            ListBorderPonts.Clear();
            foreach (var item in _list_border_points)
            {
                try
                {
                    if (centerImageBorder.X >= centerImageIn.X && centerImageBorder.Y >= centerImageIn.Y)
                    {
                        ImageInGray.Data[item._y - vector.Y, item._x - vector.X, 0] = 255;
                        ListBorderPonts.Add(new DatePoint(item._x - vector.X, item._y - vector.Y, 0));
                    }
                    else if (centerImageBorder.X >= centerImageIn.X && centerImageBorder.Y <= centerImageIn.Y)
                    {
                        ImageInGray.Data[item._y + vector.Y, item._x - vector.X, 0] = 255;
                        ListBorderPonts.Add(new DatePoint(item._x - vector.X, item._y + vector.Y, 0));
                    }
                    else if (centerImageBorder.X <= centerImageIn.X && centerImageBorder.Y >= centerImageIn.Y)
                    {
                        ImageInGray.Data[item._y - vector.Y, item._x + vector.X, 0] = 255;
                        ListBorderPonts.Add(new DatePoint(item._x + vector.X, item._y - vector.Y, 0));
                    }
                    else if (centerImageBorder.X <= centerImageIn.X && centerImageBorder.Y <= centerImageIn.Y)
                    {
                        ImageInGray.Data[item._y + vector.Y, item._x + vector.X, 0] = 255;
                        ListBorderPonts.Add(new DatePoint(item._x + vector.X, item._y + vector.Y, 0));
                    }
                }
                catch (Exception)
                {
                    continue;
                    throw;
                }
            }
            foreach (var item in pointsPlace)
            {
                ImageInGray.Data[item._y, item._x, 0] = 255;
            }
            return(ImageInGray);
        }