c# GDI+ 다른 글꼴 그리기 문자열

2953 단어 문자열
문자열에는 한자와 자모가 있을 수 있으므로 한자와 자모는 각각 다른 글씨체로 직접po 코드를 그립니다
 Bitmap bmp = new Bitmap(iWidth, iHeight);

            Graphics g = Graphics.FromImage(bmp);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            g.FillRectangle(new SolidBrush(Color.FromArgb(0, 90, 169)), new Rectangle(0, 0, bmp.Width, bmp.Height));

            if (IFYY)

            {

                Font arial = new System.Drawing.Font("Arial", 46F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));

                StringFormat test = StringFormat.GenericTypographic;

                SizeF size = g.MeasureString(strText, font, 1062, test);

                float fX = (1062 - size.Width) / 2 + 348;

                float fY = (58 - size.Height) / 2 + 960;

                float rowSpace = 0f;

                for (int i = 0; i < strText.Length; i++)

                {

                    string ss = strText[i].ToString();

                    if (ISLetter(strText[i]))

                    {

                        SizeF sf = g.MeasureString(ss, arial);

                        g.DrawString(ss, arial, brushWhite, fX, fY);

                        if (ss == " ")

                        {

                            fX += g.MeasureString(ss, arial).Width + rowSpace;

                        }

                        else

                        {

                            fX += g.MeasureString(ss, arial, 100, test).Width + rowSpace;

                        }

                        //g.DrawString(strText[i].ToString(), arial, brushWhite, rectF, format);

                    }

                    else

                    {

                        g.DrawString(ss, font, brushWhite, fX, fY);

                        fX += g.MeasureString(ss, font, 100, test).Width + rowSpace;

                    }

                    //fX += rowSpace;

                }

            }

            else

            {

                g.DrawString(strText, font, brushWhite, rectF, format);

            }

            

            //g.DrawString(strText, arial, brushWhite, rectF, format);

            g.Dispose();

            bmp.RotateFlip(RotateFlipType.Rotate180FlipX);

            return bmp;

        }



        private static bool ISLetter(char c)

        {

            bool letter = false;

            if (c > 127)

            {

                letter = false;

            }

            else

            {

                letter = true;

            }

            return letter;

        }


주의해야 할 점:
       StringFormat test = StringFormat.GenericTypographic;

                SizeF size = g.MeasureString(strText, font, 1062, test);
Graphics.MeasureString() , ,

좋은 웹페이지 즐겨찾기