예제 #1
0
        public static void Vizual_PictureAsRaw(ZArrayDescriptor zArrayDescriptor, PictureBox pictureBox)
        {
            int width  = zArrayDescriptor.width;
            int height = zArrayDescriptor.height;

            if (width == 0 || height == 0)
            {
                MessageBox.Show("Vizual_Picture: width == 0 || height == 0"); return;
            }

            Bitmap     bmp2  = new Bitmap(width, height);
            BitmapData data2 = ImageProcessor.getBitmapData(bmp2);

            for (int j = 0; j < width; j++)
            {
                for (int i = 0; i < height; i++)
                {
                    int c;

                    c = Convert.ToInt32(zArrayDescriptor.array[j, i]);

                    Color c1 = Color.FromArgb(c, c, c);
                    ImageProcessor.setPixel(data2, j, i, c1);
                }
            }

            pictureBox.Image = bmp2;
            bmp2.UnlockBits(data2);
        }
        // Конструктор array из PictureBox
        // если изображение меньше чем  Nx,  Ny, то оно помещается в центре, а по краям 0
        // если изображение больше, то оно обрезается
        public ZArrayDescriptor(PictureBox pictureBox01, int Nx, int Ny)
        {
            if (pictureBox01.Image == null)
            {
                return;
            }


            width  = Nx;
            height = Ny;
            array  = new double[Nx, Ny];

            int NxP = pictureBox01.Image.Width;
            int NyP = pictureBox01.Image.Height;

            Bitmap     bmp2  = new Bitmap(pictureBox01.Image, NxP, NyP);
            BitmapData data2 = ImageProcessor.getBitmapData(bmp2);

            // Color.FromArgb(c, c, c);
            // c1 = ImageProcessor.getPixel(i, j, data1);                       // c1 = bmp1.GetPixel(i, j);
            // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r));   // bmp2.SetPixel(j, i, c1);
            // bmp5.UnlockBits(data5);

            //MessageBox.Show("Nx =" + Convert.ToString(Nx) + "Ny =" + Convert.ToString(Ny));
            //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height));
            int N2 = 0;

            if (Nx > NxP)
            {
                N2 = (Nx - NxP) / 2;
                for (int i = 0; i < N2; i++)
                {
                    for (int j = 0; j < Ny; j++)
                    {
                        array[i, j] = 0.0;
                    }
                }
                for (int i = N2; i < Nx - N2; i++)
                {
                    Stolb(i, N2, data2, Ny, NyP, ColorModeEnum.Uknown);
                }
                for (int i = Nx - N2; i < Nx; i++)
                {
                    for (int j = 0; j < Ny; j++)
                    {
                        array[i, j] = 0.0;
                    }
                }
            }
            else
            {
                for (int i = 0; i < Nx; i++)
                {
                    Stolb(i, 0, data2, Ny, NyP, ColorModeEnum.Uknown);
                }
            }

            bmp2.UnlockBits(data2);
        }
예제 #3
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        unsafe public static void floodImage(int x, int y, Color fillColor, Image someImage, bool squareStep, Color borderColor)
        {
            List <Point> listOfPoints = new List <Point>();

            listOfPoints.Add(new Point(x, y));

            BitmapData imageData = ImageProcessor.getBitmapData((Bitmap)(someImage));

            ImageProcessor.setPixel(imageData, x, y, fillColor);

            for (; ;)
            {
                if (listOfPoints.Count == 0)
                {
                    break;
                }

                List <Point> pointsToDelete = new List <Point>();
                List <Point> pointsToAdd    = new List <Point>();

                foreach (Point currentPoint in listOfPoints)
                {
                    if (squareStep == false)
                    {
                        drawPixel(currentPoint.X, currentPoint.Y, fillColor, pointsToAdd, imageData, someImage, borderColor);
                    }
                    else
                    {
                        drawPixelSquareStep(currentPoint.X, currentPoint.Y, fillColor, pointsToAdd, imageData, someImage, borderColor);
                    }

                    pointsToDelete.Add(currentPoint);
                }

                List <Point> result = listOfPoints.Except(pointsToDelete).ToList();
                listOfPoints = result;

                listOfPoints.AddRange(pointsToAdd);

                pointsToDelete = null;
                pointsToAdd    = null;
                result         = null;
            }

            ((Bitmap)(someImage)).UnlockBits(imageData);
        }
        public ZArrayDescriptor(Bitmap bitmap, ColorModeEnum colorMode)
        {
            BitmapData bitmapData = ImageProcessor.getBitmapData(bitmap);

            width  = bitmap.Width;
            height = bitmap.Height;
            array  = new double[width, height];

            int NxP = bitmap.Width;
            int NyP = bitmap.Height;

            //for (int i = 0; i < NxP; i++) Stolb(i, 0, bitmapData, NyP, NyP);

            int Nx = NxP;
            int Ny = NyP;

            int N2 = (Nx - NxP) / 2;

            for (int i = 0; i < N2; i++)
            {
                for (int j = 0; j < Ny; j++)
                {
                    array[i, j] = 0.0;
                }
            }
            for (int i = N2; i < Nx - N2; i++)
            {
                Stolb(i, N2, bitmapData, Ny, NyP, colorMode);
            }
            for (int i = Nx - N2; i < Nx; i++)
            {
                for (int j = 0; j < Ny; j++)
                {
                    array[i, j] = 0.0;
                }
            }

            bitmap.UnlockBits(bitmapData);
        }
예제 #5
0
        private Image CreateImageFromArrayDescriptor(ZArrayDescriptor zArrayDescriptor)
        {
            int width  = zArrayDescriptor.width;
            int height = zArrayDescriptor.height;

            Bitmap     bitmap     = new Bitmap(width, height);
            BitmapData bitmapData = ImageProcessor.getBitmapData(bitmap);

            int intensity = 0;

            for (int j = 0; j < width; j++)
            {
                for (int i = 0; i < height; i++)
                {
                    intensity = Convert.ToInt32(zArrayDescriptor.array[j, i]);

                    Color color = Color.FromArgb(intensity, intensity, intensity);
                    ImageProcessor.setPixel(bitmapData, j, i, color);
                }
            }

            bitmap.UnlockBits(bitmapData);
            return(bitmap);
        }
예제 #6
0
        public static void Vizual_Circle(ZArrayDescriptor zArrayDescriptor, PictureBox pictureBox01, int x0, int y0, int radius)
        {
            // c1 = ImageProcessor.getPixel(i, j, data1);                       // c1 = bmp1.GetPixel(i, j);
            // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r));   // bmp2.SetPixel(j, i, c1);
            // bmp5.UnlockBits(data5);
            if (pictureBox01 == null)
            {
                MessageBox.Show("pictureBox01 == null"); return;
            }
            if (zArrayDescriptor == null)
            {
                MessageBox.Show("ZArrayDescriptor array == null"); return;
            }

            int width  = zArrayDescriptor.width;
            int height = zArrayDescriptor.height;

            if (width == 0 || height == 0)
            {
                MessageBox.Show("width == 0 || height == 0"); return;
            }

            Bitmap     bmp2  = new Bitmap(width, height);
            BitmapData data2 = ImageProcessor.getBitmapData(bmp2);

            double max = SumClass.getMax(zArrayDescriptor);
            double min = SumClass.getMin(zArrayDescriptor);

            //MessageBox.Show("max = " + Convert.ToString(max) + " min = " + Convert.ToString(min));

            if (Math.Abs(max - min) < 0.0000001)
            {
                // MessageBox.Show("max = min");
                int c = 0;
                if (max < 255 && max > 0.0)
                {
                    c = Convert.ToInt32(max);
                }
                if (max > 255)
                {
                    c = 255;
                }
                if (max < 0)
                {
                    c = 0;
                }
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }
                pictureBox01.Image = bmp2;
                bmp2.UnlockBits(data2);
                return;
            }
            if (max != min)
            {
                double mxmn = 255.0 / (max - min);
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        int   c  = Convert.ToInt32((zArrayDescriptor.array[j, i] - min) * mxmn);
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }

                Color c2 = Color.FromArgb(255, 128, 255);
                DrawCircle(data2, x0, y0, radius, c2);                           // Рисование окружности  цветом

                Fill_Circle_Outside(zArrayDescriptor, data2, width, height, c2); // Заполнение цветом снаружи


                pictureBox01.Image = bmp2;
                bmp2.UnlockBits(data2);
                return;
            }
        }
예제 #7
0
        //---------------------------------------------------------------------------------------------------------------------
        //
        //         Из ZArrayDescriptor.array в PictureBox
        //
        public static void Vizual_Picture(ZArrayDescriptor zArrayDescriptor, PictureBox pictureBox01)
        {
            // c1 = ImageProcessor.getPixel(i, j, data1);                       // c1 = bmp1.GetPixel(i, j);
            // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r));   // bmp2.SetPixel(j, i, c1);
            // bmp5.UnlockBits(data5);

            if (pictureBox01 == null)
            {
                MessageBox.Show("Vizual_Picture: pictureBox01 == null"); return;
            }
            if (zArrayDescriptor == null)
            {
                MessageBox.Show("Vizual_Picture: ZArrayDescriptor array == null"); return;
            }

            int width  = zArrayDescriptor.width;
            int height = zArrayDescriptor.height;

            if (width == 0 || height == 0)
            {
                MessageBox.Show("Vizual_Picture: width == 0 || height == 0"); return;
            }

            Bitmap     bmp2  = new Bitmap(width, height);
            BitmapData data2 = ImageProcessor.getBitmapData(bmp2);

            double max = SumClass.getMax(zArrayDescriptor);
            double min = SumClass.getMin(zArrayDescriptor);

            //MessageBox.Show("max = " + Convert.ToString(max) + " min = " + Convert.ToString(min));

            if (Math.Abs(max - min) < 0.0000001)
            {
                // MessageBox.Show("max = min");
                int c = 0;
                if (max < 255 && max > 0.0)
                {
                    c = Convert.ToInt32(max);
                }
                if (max > 255)
                {
                    c = 255;
                }
                if (max < 0)
                {
                    c = 0;
                }
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }
                pictureBox01.Image = bmp2;
                bmp2.UnlockBits(data2);
                return;
            }

            if (max != min)
            {
                double mxmn = 255.0 / (max - min);
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        int c;
                        try
                        {
                            c = Convert.ToInt32((zArrayDescriptor.array[j, i] - min) * mxmn);
                        }
                        catch (System.OverflowException)
                        {
                            c = 0;
                        }

                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }
                pictureBox01.Image = bmp2;
                bmp2.UnlockBits(data2);
                return;
            }
        }
        //---------------------------------------------------------------------------------------------------------------------
        //
        //         Из ZArrayDescriptor.array в PictureBox
        //
        public void Double_Picture(PictureBox pictureBox01)
        {
            Bitmap     bmp2  = new Bitmap(width, height);
            BitmapData data2 = ImageProcessor.getBitmapData(bmp2);

            // c1 = ImageProcessor.getPixel(i, j, data1);                       // c1 = bmp1.GetPixel(i, j);
            // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r));   // bmp2.SetPixel(j, i, c1);
            // bmp5.UnlockBits(data5);
            if (pictureBox01 == null)
            {
                MessageBox.Show("pictureBox01 == null");           return;
            }
            if (array == null)
            {
                MessageBox.Show("ZArrayDescriptor array == null"); return;
            }

            double max = double.MinValue;
            double min = double.MaxValue;

            for (int j = 0; j < width; j++)
            {
                for (int i = 0; i < height; i++)
                {
                    min = Math.Min(min, array[i, j]);
                    max = Math.Max(max, array[i, j]);
                }
            }
            //MessageBox.Show("max = " + Convert.ToString(max) + " min = " + Convert.ToString(min));

            if (Math.Abs(max - min) < 0.0000001)
            {
                // MessageBox.Show("max = min");
                int c = 0;
                if (max < 255 && max > 0.0)
                {
                    c = Convert.ToInt32(max);
                }
                if (max > 255)
                {
                    c = 255;
                }
                if (max < 0)
                {
                    c = 0;
                }
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }
                pictureBox01.Image = bmp2;
                bmp2.UnlockBits(data2);
                return;
            }
            if (max != min)
            {
                double mxmn = 255.0 / (max - min);
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        int   c  = Convert.ToInt32((array[j, i] - min) * mxmn);
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }
                pictureBox01.Image = bmp2;
                bmp2.UnlockBits(data2);
                return;
            }
        }
예제 #9
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///          Приведение изображения к диапазону без ZArrayDescriptor (перегруженный метод)
        /// </summary>
        public static void Range_Picture(PictureBox pictureBox01, double min, double max)
        {
            // c1 = ImageProcessor.getPixel(i, j, data1);                       // c1 = bmp1.GetPixel(i, j);
            // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r));   // bmp2.SetPixel(j, i, c1);
            // bmp5.UnlockBits(data5);
            if (pictureBox01 == null)
            {
                MessageBox.Show("SumClass pictureBox01 == null"); return;
            }


            int width  = pictureBox01.Image.Width;
            int height = pictureBox01.Image.Height;

            Bitmap     bmp2  = new Bitmap(width, height);
            BitmapData data2 = ImageProcessor.getBitmapData(bmp2);

            Bitmap     bmp1  = new Bitmap(pictureBox01.Image, width, height);
            BitmapData data1 = ImageProcessor.getBitmapData(bmp1);


            if (max == min)
            {
                for (int j = 0; j < width; j++)
                {
                    for (int i = 0; i < height; i++)
                    {
                        int c = 0;
                        if (max < 255 && max > 0.0)
                        {
                            c = Convert.ToInt32(max);
                        }
                        if (max > 255)
                        {
                            c = 255;
                        }
                        if (max < 0)
                        {
                            c = 0;
                        }
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, j, i, c1);
                    }
                }
            }
            if (max != min)
            {
                double mxmn = 255.0 / (max - min);
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        //double fc = zArrayPicture.array[j, i];
                        Color  c2 = ImageProcessor.getPixel(i, j, data1);
                        double fc = c2.G;
                        if (fc > max)
                        {
                            fc = max;
                        }
                        if (fc < min)
                        {
                            fc = min;
                        }
                        int   c  = Convert.ToInt32((fc - min) * mxmn);
                        Color c1 = Color.FromArgb(c, c, c);
                        ImageProcessor.setPixel(data2, i, j, c1);
                    }
                }
            }
            pictureBox01.Image = bmp2;
            bmp2.UnlockBits(data2);
        }