Esempio n. 1
0
        private Bitmap GetGrayBitmap(int xOff, int yOff, int xSize, int ySize)
        {
            Rect rect = new Rect(xOff, yOff, xSize, ySize);

            RasterData rasterData = rasterDatas[0];

            double[] data = rasterData.ReadRasterData((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);

            //float min = data.Min();
            //float max = data.Max();
            //double denominator = max - min;
            double min         = rasterData.MinMax[0];
            double max         = rasterData.MinMax[1];
            double denominator = max - min;

            const int bpp = 4;

            byte[] bytes = new byte[xSize * ySize * bpp];
            for (int row = 0; row < ySize; row++)
            {
                for (int col = 0; col < xSize; col++)
                {
                    double result = data[row * xSize + col];
                    byte   value  = (byte)(int)((result - min) * 255 / denominator);

                    bytes[row * xSize * bpp + col * bpp]     = value;
                    bytes[row * xSize * bpp + col * bpp + 1] = value;
                    bytes[row * xSize * bpp + col * bpp + 2] = value;
                    bytes[row * xSize * bpp + col * bpp + 3] = 255;
                }
            }

            return(ImageControl.GetBitmap(bytes, xSize, ySize, PixelFormat.Format32bppRgb));
        }
Esempio n. 2
0
        private Bitmap GetRgbBitmap(int xOff, int yOff, int xSize, int ySize)
        {
            Rect rect = new Rect();

            rect.X      = xOff;
            rect.Y      = yOff;
            rect.Width  = xSize;
            rect.Height = ySize;

            //byte[] R = new byte[xSize * ySize];
            //byte[] G = new byte[xSize * ySize];
            //byte[] B = new byte[xSize * ySize];

            double[] R = new double[xSize * ySize];
            double[] G = new double[xSize * ySize];
            double[] B = new double[xSize * ySize];

            for (int i = 0; i < rasterDatas.Count; i++)
            {
                if (rasterDatas[i].Band.GetRasterColorInterpretation() == ColorInterp.GCI_RedBand)
                {
                    R = rasterDatas[i].GetRaster(rect);
                    //R = GetByteValue(data, xSize, ySize, rasterDatas[i].Data.Min(), rasterDatas[i].Data.Max());
                }
                else if (rasterDatas[i].Band.GetRasterColorInterpretation() == ColorInterp.GCI_GreenBand)
                {
                    G = rasterDatas[i].GetRaster(rect);
                    //G = GetByteValue(data, xSize, ySize, rasterDatas[i].Data.Min(), rasterDatas[i].Data.Max());
                }
                else if (rasterDatas[i].Band.GetRasterColorInterpretation() == ColorInterp.GCI_BlueBand)
                {
                    B = rasterDatas[i].GetRaster(rect);
                    //B = GetByteValue(data, xSize, ySize, rasterDatas[i].Data.Min(), rasterDatas[i].Data.Max());
                }
            }

            double min         = rasterDatas[0].Data.Min();
            double max         = rasterDatas[0].Data.Max();
            double denominator = max - min;

            const int bpp = 4;

            byte[] bytes = new byte[xSize * ySize * bpp];
            for (int row = 0; row < ySize; row++)
            {
                for (int col = 0; col < xSize; col++)
                {
                    var red   = R[row * xSize + col];
                    var green = G[row * xSize + col];
                    var blue  = B[row * xSize + col];

                    byte redByte   = (byte)(int)((red - min) * 255 / denominator);
                    byte greenByte = (byte)(int)((green - min) * 255 / denominator);
                    byte blueByte  = (byte)(int)((blue - min) * 255 / denominator);

                    bytes[row * xSize * bpp + col * bpp]     = blueByte;
                    bytes[row * xSize * bpp + col * bpp + 1] = greenByte;
                    bytes[row * xSize * bpp + col * bpp + 2] = redByte;

                    if (R[row * xSize + col] + G[row * xSize + col] + B[row * xSize + col] == 0)
                    {
                        bytes[row * xSize * bpp + col * bpp + 3] = 0;
                    }
                    else
                    {
                        bytes[row * xSize * bpp + col * bpp + 3] = 255;
                    }
                }
            }

            return(ImageControl.GetBitmap(bytes, xSize, ySize, PixelFormat.Format32bppArgb));
        }