C#绘图 海报商品标题绘图代码

 

                    //商品标题                               
                    int charNumber = 15;//charNumber为要截取的每段的长度
                    int fontSize = 25;//商品标题字体大小
                    if (goodTitle.Length > charNumber)
                    {
                        ArrayList arrlist = new ArrayList();
                        string tempStr = goodTitle;
                        for (int i = 0; i < tempStr.Length; i += charNumber)
                        {
                            if ((tempStr.Length - i) > charNumber)
                            {
                                arrlist.Add(tempStr.Substring(i, charNumber));
                            }
                            else
                            {
                                arrlist.Add(tempStr.Substring(i));
                            }
                        }
                        int y = 596;
                        foreach (var item in arrlist)
                        {
                            y += 40;//每行隔开的距离
                            Brush brushGoodTitle = new SolidBrush(Color.Black);
                            Font fontGoodTitle = new Font("黑体", fontSize, FontStyle.Bold);
                            tengxunGra.DrawString(item.ToString(), fontGoodTitle, brushGoodTitle, 25, y);
                        }
                    }
                    else
                    {
                        Brush brushGoodTitle = new SolidBrush(Color.Black);
                        Font fontGoodTitle = new Font("黑体", fontSize, FontStyle.Bold);
                        tengxunGra.DrawString(goodTitle, fontGoodTitle, brushGoodTitle, 25, 626);//x,y
                    }

 

posted on 2022-09-20 16:45  Jankie1122  阅读(43)  评论(0编辑  收藏  举报