コード例 #1
0
        //------------------------------------------------------------------------------------------------
        //Создание изображения из матриц R G B
        public static WriteableBitmap CreateWriteableBitmapFromMatricesRGB(
            IntegerMatrix redMatrix, IntegerMatrix greenMatrix, IntegerMatrix blueMatrix,
            int dpiX, int dpiY
            )
        {
            int             width       = redMatrix.ColumnCount;
            int             height      = redMatrix.RowCount;
            PixelFormat     pixelFormat = PixelFormats.Bgra32;
            WriteableBitmap newImage    = WriteableBitmapCreator.CreateWriteableBitmap
                                              (width, height, dpiX, dpiY, pixelFormat);
            WriteableBitmapWrapper wrapper = WriteableBitmapWrapper.Create(newImage);

            byte[] pixelBytes     = new byte[4 * width * height]; //BGRA
            int    pixelByteIndex = 0;

            for (int y = 0; y < newImage.PixelHeight; y++)
            {
                for (int x = 0; x < newImage.PixelWidth; x++)
                {
                    pixelBytes[pixelByteIndex++] = Convert.ToByte(blueMatrix[y, x]);
                    pixelBytes[pixelByteIndex++] = Convert.ToByte(greenMatrix[y, x]);
                    pixelBytes[pixelByteIndex++] = Convert.ToByte(redMatrix[y, x]);
                    pixelBytes[pixelByteIndex++] = byte.MaxValue;
                }
            }

            wrapper.WritePixels(pixelBytes);

            return(newImage);
        }
コード例 #2
0
        //------------------------------------------------------------------------------------------------
        //Создание изображения из матрицы интенсивностей серого по шаблону
        public static WriteableBitmap CreateGrayScaleWriteableBitmapFromMatrix(
            RealMatrix grayScaleMatrix,
            int dpiX, int dpiY, BitMask2D bitMask
            )
        {
            int             pixelWidth      = grayScaleMatrix.ColumnCount;
            int             pixelHeight     = grayScaleMatrix.RowCount;
            WriteableBitmap writeableBitmap = WriteableBitmapCreator.CreateWriteableBitmap
                                                  (pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Bgra32);
            WriteableBitmapWrapper bitmapWrapper = WriteableBitmapWrapper.Create(writeableBitmap);

            for (int x = 0; x < pixelWidth; x++)
            {
                for (int y = 0; y < pixelHeight; y++)
                {
                    if (bitMask[y, x] == true)
                    {
                        int  grayIntensity = ( int )Math.Round(grayScaleMatrix[y, x]);
                        byte red, green, blue;
                        red = green = blue = Convert.ToByte(grayIntensity);
                        Color color = Color.FromRgb(red, green, blue);
                        bitmapWrapper.SetPixelColor(x, y, color);
                    }
                }
            }
            return(writeableBitmap);
        }
コード例 #3
0
        //-----------------------------------------------------------------------------------------------
        //Матрица интенсивностей серого
        public static RealMatrix GetGrayScaleMatrixFromWriteableBitmap(WriteableBitmap bitmap)
        {
            WriteableBitmapWrapper bitmapWrapper   = WriteableBitmapWrapper.Create(bitmap);
            RealMatrix             grayScaleMatrix = bitmapWrapper.GetGrayScaleMatrix();

            return(grayScaleMatrix);
        }
コード例 #4
0
 //--------------------------------------------------------------------------------------------------
 //Сохранение изображений в файлы
 public static void SaveWrtieableBitmapsToPngFile(WriteableBitmap[] bitmaps, string[] fileNames)
 {
     for (int index = 0; index < 0; index++)
     {
         WriteableBitmap        bitmap        = bitmaps[index];
         WriteableBitmapWrapper bitmapWrapper = WriteableBitmapWrapper.Create(bitmap);
         string fileName = fileNames[index];
         bitmapWrapper.SaveToPngFile(fileName);
     }
 }
コード例 #5
0
 //-------------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------------------------------
 //Матрицы интенсивностей серого
 public static RealMatrix[] GetGrayScaleMatricesFromWriteableBitmaps(params WriteableBitmap[] bitmaps)
 {
     RealMatrix[] grayScaleMatrices = new RealMatrix[bitmaps.Length];
     for (int index = 0; index < bitmaps.Length; index++)
     {
         WriteableBitmap bitmap          = bitmaps[index];
         RealMatrix      grayScaleMatrix =
             WriteableBitmapWrapper.GetGrayScaleMatrixFromWriteableBitmap(bitmap);
         grayScaleMatrices[index] = grayScaleMatrix;
     }
     return(grayScaleMatrices);
 }
コード例 #6
0
 //-------------------------------------------------------------------------------------------------
 //Обрезанные изображения
 public static WriteableBitmap[] GetSubBitmaps(
     WriteableBitmap[] bitmaps, System.Drawing.Point leftTop, System.Drawing.Point rightBottom
     )
 {
     WriteableBitmap[] subBitmaps = new WriteableBitmap[bitmaps.Length];
     for (int index = 0; index < bitmaps.Length; index++)
     {
         WriteableBitmap        bitmap    = bitmaps[index];
         WriteableBitmapWrapper wrapper   = WriteableBitmapWrapper.Create(bitmap);
         WriteableBitmap        subBitmap = wrapper.GetSubBitmap(leftTop, rightBottom);
         subBitmaps[index] = subBitmap;
     }
     return(subBitmaps);
 }
コード例 #7
0
        //-----------------------------------------------------------------------------------------------------


        //-----------------------------------------------------------------------------------------------------
        //Обрезка изображения
        public WriteableBitmap GetSubBitmap(System.Drawing.Point leftTop, System.Drawing.Point rightBottom)
        {
            int newImageWidth  = Convert.ToInt32(Math.Abs(rightBottom.X - leftTop.X)) + 1;
            int newImageHeight = Convert.ToInt32(Math.Abs(rightBottom.Y - leftTop.Y)) + 1;

            media.PixelFormat pixelFormat = this.Image.Format;
            int             dpiX          = Convert.ToInt32(OS.OS.SystemDpiX);
            int             dpiY          = Convert.ToInt32(OS.OS.SystemDpiY);
            WriteableBitmap newBitmap     = WriteableBitmapCreator.CreateWriteableBitmap
                                                (newImageWidth, newImageHeight, dpiX, dpiY, pixelFormat);
            WriteableBitmapWrapper newImageWrapper = WriteableBitmapWrapper.Create(newBitmap);

            for (int y = leftTop.Y, newY = 0; y <= rightBottom.Y; y++, newY++)
            {
                for (int x = leftTop.X, newX = 0; x <= rightBottom.X; x++, newX++)
                {
                    media.Color color = this.GetPixelColor(x, y);
                    newImageWrapper.SetPixelColor(newX, newY, color);
                }
            }

            return(newBitmap);
        }