private void SetFontImage(BitmapSource image) { int stride = (image.Format.BitsPerPixel * image.PixelWidth + 7) / 8; byte[] data = new byte[image.PixelHeight * stride]; image.CopyPixels(data, stride, 0); ImageData BMP = new ImageData(data, image.Format, image.PixelWidth, image.PixelHeight); List <byte[]> BMPdata = new List <byte[]>(); int row = 0; int column = 0; for (int i = 0; i < Header.Glyphs.Count; i++) { BMPdata.Add(ImageData.Crop(BMP, new ImageData.Rect(column * Header.Glyphs.Size1, row * Header.Glyphs.Size2, Header.Glyphs.Size1, Header.Glyphs.Size2)).Data); column++; if (column == 16) { row++; column = 0; } } if (Header.Glyphs.BitsPerPixel == 4) { Util.ReverseByteInList(BMPdata); } Compressed.CompressData(BMPdata); }
public void SetImage(BitmapSource image) { PixelFormat pixelFormat; if (Header.Glyphs.BitsPerPixel == 4) { pixelFormat = PixelFormats.Indexed4; } else if (Header.Glyphs.BitsPerPixel == 8) { pixelFormat = PixelFormats.Indexed8; } else { throw new Exception("FNT: Unknown Pixel Format"); } FormatConvertedBitmap bitmap = new FormatConvertedBitmap(); bitmap.BeginInit(); bitmap.Source = image; bitmap.DestinationFormat = pixelFormat; bitmap.DestinationPalette = GetImagePalette(Palette.Pallete); bitmap.EndInit(); int stride = (bitmap.Format.BitsPerPixel * bitmap.PixelWidth + 7) / 8; byte[] data = new byte[bitmap.PixelHeight * stride]; bitmap.CopyPixels(data, stride, 0); ImageData BMP = new ImageData(data, bitmap.Format, bitmap.PixelWidth, bitmap.PixelHeight); List <byte[]> BMPdata = new List <byte[]>(); int row = 0; int column = 0; for (int i = 0; i < Header.Glyphs.Count; i++) { BMPdata.Add(ImageData.Crop(BMP, new ImageData.Rect(column * Header.Glyphs.Size1, row * Header.Glyphs.Size2, Header.Glyphs.Size1, Header.Glyphs.Size2)).Data); column++; if (column == 16) { row++; column = 0; } } if (Header.Glyphs.BitsPerPixel == 4) { Util.ReverseByteInList(BMPdata); } Compressed.CompressData(BMPdata); }
public void SetBitmap(Bitmap image) { PixelFormat pixelFormat; if (Header.Glyphs.BitsPerPixel == 4) { pixelFormat = PixelFormats.Indexed4; } else if (Header.Glyphs.BitsPerPixel == 8) { pixelFormat = PixelFormats.Indexed8; } else { throw new Exception("FNT: Unknown Pixel Format"); } var palette = Palette.GetImagePalette(); var tempBitmap = image.ConvertTo(pixelFormat, palette).CopyData(); int srcStride = ImageHelper.GetStride(pixelFormat, image.Width); int rowSize = srcStride * Header.Glyphs.Size2; int columnStride = ImageHelper.GetStride(pixelFormat, Header.Glyphs.Size1); int dstDataSize = columnStride * Header.Glyphs.Size2; List <byte[]> BMPdata = new List <byte[]>(); int row = 0; int column = 0; for (int i = 0; i < Header.Glyphs.Count; i++) { byte[] glyph = new byte[dstDataSize]; for (int k = 0; k < Header.Glyphs.Size2; k++) { byte[] temp = tempBitmap.SubArray (row * rowSize + column * columnStride + k * srcStride, columnStride); Buffer.BlockCopy(temp, 0, glyph, k * columnStride, columnStride); } column++; if (column == 16) { row++; column = 0; } BMPdata.Add(glyph); } if (Header.Glyphs.BitsPerPixel == 4) { AuxiliaryLibraries.Tools.ArrayTool.ReverseByteInList(BMPdata); } Compressed.CompressData(BMPdata); }