drawstring

How to align text drawn by SpriteBatch.DrawString?

我是研究僧i 提交于 2019-12-04 10:37:03
问题 Is there an easy way to align text to the right and center (instead of default left)? 回答1: The first step is to measure the string using SpriteFont.MeasureString(). Then, for example if you want to draw it to the left of a certain point, instead of to the right as is the default, then you need to subtract the X width of the measurement from the text drawing origin. If you want it to be centered, then you can use half the measurement, etc. 回答2: I use this code: [Flags] public enum Alignment {

how to improve printed text quality after using “graphics.DrawString”?

▼魔方 西西 提交于 2019-12-04 04:11:32
问题 I have a problem with my text quality after printing ! it's not smooth and antialiases! This is the story : I create a graphic from a bitmap ( Graphics.FromImage(MyBitmap) ) and I think it's the start point of my problem because I can't use PrintPageEvenArg(e) , but I have no other choice! after that I begin writing some text on this graphic: by reading the answers of similar Questions in this site and some others , I made some changes on my graphics properties such as smoothingMode ,

How to Change Font Size in drawString Java

最后都变了- 提交于 2019-12-03 14:33:50
问题 How to make the font size bigger in g.drawString("Hello World",10,10); ? 回答1: g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); Where fontSize is a int. The API for drawString states that the x and y parameters are coordinates, and have nothing to do with the size of the text. 回答2: Because you can't count on a particular font being available, a good approach is to derive a new font from the current font. This gives you the same family, weight, etc. just larger... Font currentFont = g

How to Change Font Size in drawString Java

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:19:23
How to make the font size bigger in g.drawString("Hello World",10,10); ? John Snow g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); Where fontSize is a int. The API for drawString states that the x and y parameters are coordinates, and have nothing to do with the size of the text. Because you can't count on a particular font being available, a good approach is to derive a new font from the current font. This gives you the same family, weight, etc. just larger... Font currentFont = g.getFont(); Font newFont = currentFont.deriveFont(currentFont.getSize() * 1.4F); g.setFont(newFont); You

Why repainting of that take so much time?

一个人想着一个人 提交于 2019-12-02 22:13:39
问题 I have something like that (the time is now displayed correctly). I have added KeyListener to the JFrame in which these JPanels are. When I press ->(right key) I want to time to increment by one and it does but it is really slow(like 3 seconds of waiting then even much longer). The algorithms in program are not the fault(checked without GUI, they're fast). Is there any way to faster the reaction ->pressing key-> changing time. The image is png so it should be fast. I call aktualizuj() every

Using custom TTF font for DrawString image rendering

折月煮酒 提交于 2019-12-02 20:35:58
I am using GDI+ on the server-side to create an image which is streamed to the user's browser. None of the standard fonts fit my requirements and so I want to load a TrueType font and use this font for drawing my strings to the graphics object: using (var backgroundImage = new Bitmap(backgroundPath)) using (var avatarImage = new Bitmap(avatarPath)) using (var myFont = new Font("myCustom", 8f)) { Graphics canvas = Graphics.FromImage(backgroundImage); canvas.DrawImage(avatarImage, new Point(0, 0)); canvas.DrawString(username, myFont, new SolidBrush(Color.Black), new PointF(5, 5)); return new

How to draw a string at an exact pixel position

独自空忆成欢 提交于 2019-12-02 01:39:58
I try to draw a string (single character) in C# into a Bitmap at an exact position with: Bitmap bmp = new Bitmap(64, 64); Graphics g = Graphics.FromImage(bmp); g.DrawString("W", font1, new SolidBrush(myColor), new Point(32,32); There is so much empty space rendered around a single letter, that I can not guess the "needed" position to draw the character to have it at the correct position at the end. By now I have the pixel exact dimension of the character (looking at bits in a separately rendered bitmap). But this information is useless, if I cannot draw the character at an exact position (e.g.

How to color individual characters and maintain proper spacing / kerning / alignment?

邮差的信 提交于 2019-12-02 01:35:10
I want to use Graphics.DrawString to draw characters using individual colors. The problem is that each time I call DrawString, I have to know where to position it (either using a Point or a Rectangle) relative to the other characters. This is almost possible when taking into account the kerning and wrapping that happens when you use DrawString in a rectangle with a StringFormat. The StringFormat is important to specify alignment, wrapping, trimming, etc. Ideally I'd be able to tell DrawString how to color each character individually. The other option is if I can measure a string in a rectangle

Centering an individual character with DrawString

两盒软妹~` 提交于 2019-12-01 06:02:05
I have tried all of the suggested ways to center text, but I can't seem to get the results I want while centering an individual character. I have a rectangle. In that rectangle I'm drawing a circle with DrawEllipse. Now I want to draw a single character inside the circle using the same rectangle and DrawString, to have it perfectly centered. Here is my basic code: StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; using (Graphics g = Graphics.FromImage(xImage)) { g.SmoothingMode = SmoothingMode

MeasureString() pads the text on the left and the right

自作多情 提交于 2019-11-30 17:35:20
I'm using GDI+ in C++. (This issue might exist in C# too). I notice that whenever I call Graphics::MeasureString() or Graphics::DrawString(), the string is padded with blank space on the left and right. For example, if I am using a Courier font, (not italic!) and I measure "P" I get 90, but "PP" gives me 150. I would expect a monospace font to give exactly double the width for "PP". My question is: is this intended or documented behaviour, and how do I disable this? RectF Rect(0,0,32767,32767); RectF Bounds1, Bounds2; graphics->MeasureString(L"PP", 1, font, Rect, &Bounds1); graphics-