Как я могу решить проблему сглаживания и битового уменьшения моего изображения
Я хотел бы:
- для придания изображению определенного размера(320х240)
-для изменения цвета до 16 бит 565
-для уменьшения цвета ( 4 бита на пиксель, 16 цветов)
проблема:
Когда я применяю фильтр к bmp-изображению(150 КБ) из (Hexstring 500 КБ): сглаживание и уменьшение цветов с помощью ProcessImageDithering и BitReduction, я пытаюсь сохранить bmp-изображение как image.bmp и получаю очень маленький файл размером 11 КБ(конечно, не желаемое изображение), который обычно должен быть около 250 КБ.
Я действительно не знаю, какую ошибку я сделал, чтобы получить этот результат
I forget to tell you: 500KB is the hex string of the image(.bmp) so when I apply dithering and bitreduction I try to convert the bitmap to a hex string(stringToTest) and this string paste in a text document in a form (0x45, 0x55 ....) and must have less than 500KB (ex: 250KB) and with this file I could with another program try to build the image to examin it
Что я уже пробовал:
private Bitmap ProcessImageDithering(BitmapImage sourceImage) { var result = new System.Drawing.Bitmap((int)sourceImage.Width, (int)sourceImage.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); return result; }
private FormatConvertedBitmap BitReduction(ImageSource myBitmapImageFit) { FormatConvertedBitmap fcb = new FormatConvertedBitmap(); fcb.BeginInit(); fcb.Source = myBitmapImageFit as BitmapSource; fcb.DestinationFormat = System.Windows.Media.PixelFormats.Indexed4; fcb.DestinationPalette = BitmapPalettes.Halftone8; fcb.EndInit(); return fcb; }
private void ApplyFilter(string path) { BootScreen = BootScreenColored;//property of ImageSource BitmapImage myBitmapImage = new BitmapImage(); // BitmapSource objects like BitmapImage can only have their properties // changed within a BeginInit/EndInit block. myBitmapImage.BeginInit(); if (path == String.Empty) { //myBitmapImage.StreamSource = new MemoryStream(this.SelectedFile.BootScreen);//boorscreen is byte[] which contains data of the image myBitmapImage.StreamSource = new MemoryStream(ImageSourceToBytes(new BmpBitmapEncoder(), BootScreenColored)); //PngBitmapEncoder } else { myBitmapImage.UriSource = new Uri(path); } myBitmapImage.DecodePixelHeight = (int)HEIGHT;//240 myBitmapImage.DecodePixelWidth = (int)WIDTH;//320 myBitmapImage.EndInit(); var result = ProcessImageDithering(myBitmapImage);//Applying dithering //Reduce colors 4 bits per pixel or 16 colors var bitmapImage = BitReduction(myBitmapImage); //BitmapImage2Bitmap(ByteToBitmapImage(bitmapBytes)).Save(@"C:\_DataFiles\image.bmp"); var newBitmap = BitmapImage2Bitmap(bitmapImage.Source as BitmapImage); byte[] newbytes = BitmapToBytes(newBitmap); string StringToTest = BitConverter.ToString(newbytes); }