示例#1
0
        private WriteableBitmap GetSubStringBitmap(string subStr, int lineHeight = 0)
        {
            int imgWidth  = 0;
            int imgHeight = LineHeight;
            int yOffSet   = 0;

            if (lineHeight > 0)
            {
                imgHeight = lineHeight;
                yOffSet   = lineHeight - LineHeight;
            }
            foreach (char c in subStr)
            {
                imgWidth += BitmapCharDic[c].CharImage.PixelWidth;
            }

            WriteableBitmap wrTmp = new WriteableBitmap(imgWidth, imgHeight);

            imgWidth = 0;
            foreach (char c in subStr)
            {
                WriteableBitmap img = BitmapCharDic[c].CharImage;
                //wrTmp.Blit(new Rect(imgWidth, 0, img.PixelWidth, imgHeight), img, new Rect(0, 0, img.PixelWidth, imgHeight));
                BitmapUtils.PasteBitmap(ref wrTmp, imgWidth, yOffSet, img);
                imgWidth += img.PixelWidth;
            }
            return(wrTmp);
        }
示例#2
0
        public void LoadChar(WriteableBitmap SourceImage, string charCfg, int LineHeight, int BaseHeigt)
        {
            // Load config
            LoadConfigFromString(charCfg);

            // Load Image fron config
            WriteableBitmap _tmp         = new WriteableBitmap(_xOffset + _xAdvance, LineHeight);
            WriteableBitmap _coreContent = SourceImage.Crop(_x, _y, _width, _height);

            BitmapUtils.PasteBitmap(ref _tmp, _xOffset, _yOffset - BaseHeigt / 2, _coreContent);
            _charImage = _tmp.Clone();
        }
示例#3
0
        public WriteableBitmap GetImageFromText(string text, int maxWidth = 800, int lineHeight = 0)
        {
            if (string.IsNullOrEmpty(text) || CharCount == 0)
            {
                return(null);
            }
            else
            {
                int             textWidth   = 0;
                int             actualWidth = 0;
                int             textLine    = 1;
                WriteableBitmap resultBmp   = null;


                foreach (char c in text)
                {
                    textWidth += BitmapCharDic[c].CharImage.PixelWidth;
                }

                if (textWidth <= maxWidth)
                {
                    resultBmp = GetSubStringBitmap(text, lineHeight);
                }

                else
                {
                    int i        = 0;
                    int j        = 0;
                    int minWidth = 0;
                    textWidth = 0;
                    int textHeight = LineHeight;
                    if (lineHeight > 0)
                    {
                        textHeight = lineHeight;
                    }
                    List <string> listSubString = new List <string>();
                    for (i = 0; i < text.Length; i++)
                    {
                        actualWidth = textWidth;
                        textWidth  += BitmapCharDic[text[i]].CharImage.PixelWidth;
                        if (textWidth > maxWidth)
                        {
                            string s = text.Substring(j, i - j - 1);
                            j = i - 1;
                            listSubString.Add(s);
                            if (actualWidth > minWidth)
                            {
                                minWidth = actualWidth;
                            }
                            textWidth = BitmapCharDic[text[i]].CharImage.PixelWidth;
                        }
                    }

                    string lastSubStr = text.Substring(j);
                    listSubString.Add(lastSubStr);
                    textLine = listSubString.Count;

                    resultBmp = new WriteableBitmap(minWidth, textLine * textHeight);

                    for (i = 0; i < listSubString.Count; i++)
                    {
                        string          s      = listSubString[i];
                        WriteableBitmap wrTmp  = GetSubStringBitmap(s, textHeight);
                        int             offset = (minWidth - wrTmp.PixelWidth) / 2;
                        BitmapUtils.PasteBitmap(ref resultBmp, offset, i * textHeight, wrTmp);
                    }
                }


                return(resultBmp);
            }
        }