모양은 사각형 (예를 들어 "hello"라고 함)이있는 모양을 가정하면 간단합니다. 따라서 사각형의 테두리를 가로 지르는 텍스트를 여러 번 쓸 것입니다 예를 들면 다음과 같습니다.도형에 텍스트를 그리는 방법은 무엇입니까? C#
hello hello hello hello
hello hello
hello hello
hello hello hello hello
그래픽 변수를 사용해야 할 필요가 있다고 가정합니다. 어떻게 해야할지 잘 모릅니다.
비트 맵 객체에 문자열을 그리기위한 코드 : 사전에
Bitmap tempp = new Bitmap(1, 1);
Graphics g = Graphics.FromImage(tempp);
SizeF w = g.MeasureString("22", new Font("Tahoma", 200));//in order to get the size of the string as a pixel measurement
Bitmap bmp = new Bitmap((int)w.Width+1, (int)w.Height+1);//the bitmap that will contain the text as a picture
RectangleF rectf = new RectangleF(0, 0, (int)w.Width+1, (int)w.Height+1);
g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
StringFormat format = new StringFormat()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
};
g.DrawString("22", new Font("Tahoma", 200), Brushes.Black, rectf, format);
g.Flush();
감사합니다. 두 번째 의견에 대한
:
hello hello hello
hel llo
hel llo
hello hello hello
당신이 문자열 - 이미지의 크기를 갖게되면, 최종 사각형의 전체 크기를 계산에, 그것을 바탕으로 모든 사본을 여러 문자열 이미지 사본을 넣어 그 자신의 좌표. 어쩌면 [이 링크] (http://stackoverflow.com/questions/1478022/c-sharp-get-a-controls-position-on-a-form)가 도움이 될 수 있습니다. –
사각형의 크기는 어떻게됩니까? 4 개의 "hello"를 연속적으로 갖기에는 너무 크지 만 5 개의 경우에는 너무 작 으면 어떨까요? 그런 다음 사각형의 크기를 조정합니까? 또는 텍스트 사이의 간격을 조정합니까? – Anthony
@Anthony 이렇게 : 그렇게 코드를 보여줄 수 없기 때문에 스레드를 편집 할 것입니다. –