public static byte[] GetBytesFromBitmap(BitmapGrid i_bitmapGridView) { byte[] i_arrOut = new byte[(i_bitmapGridView.getGridWidth() / 8) * i_bitmapGridView.getGridHeight()]; //for (int byteCounter = 0; byteCounter < i_arrOut.Length; ) int byteCounter = 0; //byte actByte = 0; { for (int actHeight = 0; actHeight < i_bitmapGridView.getGridHeight(); actHeight++) { for (int actLineBit = 0; actLineBit < i_bitmapGridView.getGridWidth(); actLineBit++) { if (actLineBit != 0 && actLineBit % 8 == 0) { byteCounter++; //next byte in out arr } bool bitValue = i_bitmapGridView.getGridBitValue(actLineBit, actHeight); if (bitValue) { ConvertRadix.setBitInByteRightToLeft(ref i_arrOut[byteCounter], (byte)(actLineBit % 8)); } } byteCounter++; //next byte in out arr } } return(i_arrOut); }
/// <summary> /// Because there is no easy range calculation supported in dot net (as compared to GDI32) that I can find, I assume that the /// unsupported values will come back as an open box, or at least identical in glyph form to a known unsupported like Arial 1024. /// (Not to be confused with Arial Unicode MS, which has basically everything.) /// </summary> /// <returns>A list of supported character subsets.</returns> public IList <CharacterSubset> GetSupportedSubsets() { List <CharacterSubset> result = new List <CharacterSubset>(); PointF topLeft = new PointF(0F, 0F); Font arialFont = new Font("Arial", 10F, FontStyle.Regular, GraphicsUnit.Pixel); Font testFont = new Font(_fontFamilyName, 10F, FontStyle.Regular, GraphicsUnit.Pixel); // ensure it will fit on bitmap Bitmap empty = new Bitmap(20, 20); Graphics g = Graphics.FromImage(empty); g.DrawString(((char)1024).ToString(), arialFont, Brushes.Black, topLeft); g.Dispose(); BitmapGrid emptyGrid = new BitmapGrid(empty); Array subsets = Enum.GetValues(typeof(CharacterSubset)); foreach (CharacterSubset code in subsets) { char c = (char)code; // first character of each subset Bitmap firstChar = new Bitmap(20, 20); Graphics tg = Graphics.FromImage(firstChar); tg.DrawString(c.ToString(), testFont, Brushes.Black, topLeft); tg.Dispose(); // Bitmap grids allow a byte by byte comparison between values BitmapGrid firstCharGrid = new BitmapGrid(firstChar); if (emptyGrid.Matches(firstCharGrid) == false) { // Since this symbol is different from the default unsuported symbol result.Add(code); } firstCharGrid.Dispose(); } return(result); }
/// <summary> /// Because there is no easy range calculation supported in dot net /// (as compared to GDI32) that I can find, I assume that the /// unsupported values will come back as an open box, or at least /// identical in glyph form to a known unsupported like Arial 1024. /// (Not to be confused with Arial Unicode MS, which has basically /// everything. /// </summary> /// <returns></returns> public IList<CharacterSubset> GetSupportedSubsets() { List<CharacterSubset> result = new List<CharacterSubset>(); PointF topLeft = new PointF(0F, 0F); Font arialFont = new Font("Arial", 10F, FontStyle.Regular, GraphicsUnit.Pixel); Font testFont = new Font(_fontFamilyName, 10F, FontStyle.Regular, GraphicsUnit.Pixel); // ensure it will fit on bitmap Bitmap empty = new Bitmap(20, 20); Graphics g = Graphics.FromImage(empty); g.DrawString(((char)1024).ToString(), arialFont, Brushes.Black, topLeft); g.Dispose(); BitmapGrid emptyGrid = new BitmapGrid(empty); Array subsets = Enum.GetValues(typeof(CharacterSubset)); foreach (CharacterSubset code in subsets) { char c = (char)code; // first character of each subset Bitmap firstChar = new Bitmap(20, 20); Graphics tg = Graphics.FromImage(firstChar); tg.DrawString(c.ToString(), testFont, Brushes.Black, topLeft); tg.Dispose(); // Bitmap grids allow a byte by byte comparison between values BitmapGrid firstCharGrid = new BitmapGrid(firstChar); if (emptyGrid.Matches(firstCharGrid) == false) { // Since this symbol is different from the default unsuported symbol result.Add(code); } firstCharGrid.Dispose(); } return result; }