Esempio n. 1
0
        public unsafe ImageSource GetText(int fontId, string text, short hueId)
        {
            ASCIIFont font = _fonts[fontId];

            int width  = font.GetWidth(text);
            int height = font.Height;

            WriteableBitmap bmp = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr555, null);

            bmp.Lock();

            int *line  = (int *)bmp.BackBuffer;
            int  delta = bmp.BackBufferStride >> 2;

            int dx = 0;

            for (int i = 0; i < text.Length; ++i)
            {
                int       c  = ((((text[i]) - 0x20) & 0x7FFFFFFF) % 224);
                ASCIIChar ch = font.Chars[c];

                int charWidth  = ch.Width;
                int charHeight = ch.Height;

                ushort[] pixels = ch.Pixels;

                for (int dy = 0; dy < charHeight; ++dy)
                {
                    int *dest = (line + (delta * (dy + (font.Height - charHeight)))) + (dx);

                    for (int k = 0; k < charWidth; ++k)
                    {
                        ushort pixel  = pixels[charWidth * dy + k];
                        *      dest++ = (pixel == 0 ? (byte)0 : (byte)255 << 24) | ((byte)((pixel & 0x7C00) >> 7) << 16) | ((byte)((pixel & 0x3E0) >> 2) << 8) | (byte)((pixel & 0x1F) << 3);
                    }
                }

                dx += charWidth;
            }

            bmp.AddDirtyRect(new Int32Rect(0, 0, width, height));
            bmp.Unlock();

            return(bmp);
        }
        public unsafe Bitmap GetText(int fontId, string text, short hueId)
        {
            ASCIIFont font = _fonts[fontId];

            int width  = font.GetWidth(text);
            int height = font.Height;

            Bitmap     bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            BitmapData bd  = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            int *line  = (int *)bd.Scan0;
            int  delta = bd.Stride >> 2;

            int dx = 0;

            for (int i = 0; i < text.Length; ++i)
            {
                int       c  = ((((text[i]) - 0x20) & 0x7FFFFFFF) % 224);
                ASCIIChar ch = font.Chars[c];

                int charWidth  = ch.Width;
                int charHeight = ch.Height;

                ushort[] pixels = ch.Pixels;

                for (int dy = 0; dy < charHeight; ++dy)
                {
                    int *dest = (line + (delta * (dy + (font.Height - charHeight)))) + (dx);

                    for (int k = 0; k < charWidth; ++k)
                    {
                        ushort pixel  = pixels[charWidth * dy + k];
                        *      dest++ = Color.FromArgb(pixel == 0 ? 0 : 255, (pixel & 0x7C00) >> 7, (pixel & 0x3E0) >> 2, (pixel & 0x1F) << 3).ToArgb();
                    }
                }

                dx += charWidth;
            }

            bmp.UnlockBits(bd);

            return(bmp);
        }