Beispiel #1
0
        public ImageDescription filter(ImageDescription inputImage)
        {
            ImageDescription outputImage = new ImageDescription();

            outputImage.sizeX = newSizeX;
            outputImage.sizeY = newSizeY;

            foreach (ColorChannelEnum colorChannel in colorChannelsToFilter)
            {
                byte[,] channel = inputImage.getColorChannel(colorChannel);
                ImageDescription temp = new ImageDescription();
                temp.sizeX     = inputImage.sizeX;
                temp.sizeY     = inputImage.sizeY;
                temp.grayscale = true;
                temp.setColorChannel(ColorChannelEnum.Gray, channel);

                Bitmap tempBitmap = ImageDescriptionUtil.convertToBitmap(temp);
                Bitmap output     = ImageDescriptionUtil.resizeImage(tempBitmap, newSizeX, newSizeY);
                temp = ImageDescriptionUtil.fromBitmap(output);
                temp.computeGrayscale();
                outputImage.setColorChannel(colorChannel, temp.gray);
            }

            if (colorChannelsToFilter.Count == 1 && colorChannelsToFilter.Contains(ColorChannelEnum.Gray))
            {
                outputImage.grayscale = true;
            }
            return(outputImage);
        }
        public static void saveToPath(ImageDescription imageDescription, string filePath, string fileExtension)
        {
            Image  imageToSave  = ImageDescriptionUtil.convertToBitmap(imageDescription);
            string fullFileName = Path.ChangeExtension(filePath, fileExtension);

            switch (fileExtension)
            {
            case ".png": imageToSave.Save(fullFileName, ImageFormat.Png); break;

            case ".jpg": imageToSave.Save(fullFileName, ImageFormat.Jpeg); break;

            case ".bmp": imageToSave.Save(fullFileName, ImageFormat.Bmp); break;

            case ".gif": imageToSave.Save(fullFileName, ImageFormat.Gif); break;

            case ".ico": imageToSave.Save(fullFileName, ImageFormat.Icon); break;

            case ".emf": imageToSave.Save(fullFileName, ImageFormat.Emf); break;

            case ".exif": imageToSave.Save(fullFileName, ImageFormat.Exif); break;

            case ".tiff": imageToSave.Save(fullFileName, ImageFormat.Tiff); break;

            case ".wmf": imageToSave.Save(fullFileName, ImageFormat.Wmf); break;

            default: imageToSave.Save(fullFileName, ImageFormat.Png); break;
            }
        }