Questions tagged [drawtext]

340 questions
229
votes
12 answers

Android Center text on canvas

I'm trying to display a text using the code below. The problem is that the text is not centered horizontally. When I set the coordinates for drawText, it sets the bottom of the text at this position. I would like the text to be drawn so that the…
Sebastian
  • 2,698
  • 2
  • 17
  • 26
109
votes
2 answers

Android Canvas.drawText

I have a view, I'm drawing with the Canvas object in the onDraw(Canvas canvas) method. My code is: Paint paint = new…
Gaz
  • 3,855
  • 6
  • 28
  • 33
51
votes
9 answers

How to align text vertically?

Target: Android >= 1.6 on a pure Canvas. Suppose I want to write a function that will draw a (width, height) large red rectangle and then draw a black Hello World text inside. I want the text to be visually in the center of the rectangle. So let's…
Leszek
  • 1,181
  • 1
  • 10
  • 21
37
votes
4 answers

Android: Canvas.drawText() text size on different screen resolutions

For my Android game I have some calls to Canvas.drawText(). For testing, I use the standard font size which seems to be working fine. However, when I bump up the resolution to a higher density, the larger images are automatically loaded but the text…
twig
  • 4,034
  • 5
  • 37
  • 47
31
votes
2 answers

Android canvas drawText y-position of text

I'm using a Canvas to create a Drawable with some background and some text. The drawable is used as a compound drawable inside an EditText. The text is drawn via drawText() on the canvas, but I do have an issue with the y-position of the drawn text…
darksaga
  • 2,166
  • 2
  • 18
  • 21
28
votes
2 answers

Python PIL bytes to Image

import PIL from PIL import Image from PIL import ImageDraw from PIL import ImageFont import urllib.request with urllib.request.urlopen('http://pastebin.ca/raw/2311595') as in_file: hex_data = in_file.read() print(hex_data) img =…
user2040602
19
votes
6 answers

FFmpeg drawtext over multiple lines

I have the code: import subprocess , os ffmpeg = "C:\\ffmpeg_10_6_11.exe" inVid = "C:\\test_in.avi" outVid = "C:\\test_out.avi" if os.path.exists( outVid ): os.remove( outVid ) proc = subprocess.Popen(ffmpeg + " -i " + inVid + ''' -vf…
Jay
  • 3,373
  • 6
  • 38
  • 55
19
votes
3 answers

Android drawText including text wrapping

I am currently creating an image editor and am attempting to draw text on top of on image using canvas.drawText(). So far I have been successful in doing this but when the user enters text that is too long, the text just continues on one line out of…
Mustafa Nasser
  • 251
  • 1
  • 4
  • 15
16
votes
9 answers

ffmpeg single quote in drawtext

I haven't been able to get ffmpeg's drawtext video filter to draw apostrophes/single quotes when they are in drawtext's "text=" parameter, even when I escape them. Double quotes work fine, and apostrophes in text loaded from a file (e.g.…
dotsam
  • 183
  • 1
  • 1
  • 5
15
votes
3 answers

The reason behind slow performance in WPF

I'm creating a large number of texts in WPF using DrawText and then adding them to a single Canvas. I need to redraw the screen in each MouseWheel event and I realized that the performance is a bit slow, so I measured the time the objects are…
Vahid
  • 5,144
  • 13
  • 70
  • 146
12
votes
1 answer

How to draw a Spanned String with Canvas.drawText in Android

I want to draw a SpannedString to a Canvas. SpannableString spannableString = new SpannableString("Hello World!"); ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.RED); BackgroundColorSpan backgroundSpan = new…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
12
votes
3 answers

center text vertically and horizontally with canvas

I'm trying to align a text in bitmap horizontally and vertically, I read several post but I can't find a solution. The bitmap is a simple image of a circle. I post my current code. More or less it works but the text is not perfectly centered, it…
greywolf82
  • 21,813
  • 18
  • 54
  • 108
11
votes
2 answers

How to position StaticLayout in android?

I want to created a wrapping text ontop of google maps api. I have been able to do this with a lot of code, but have been working on a better way. My latest attempt is to use the StaticLayout class and the text is wrapping, but I do not know how…
Nick
  • 161
  • 1
  • 7
11
votes
2 answers

how to use DrawText() to write text in a given window whose handle is known?

I want to know how to write text on a particular window starting at a given location in the window using the Windows API. For example if the coordinates within the window where the text is to be written are (x,y) = (40,10) then what do I need to do…
Vicky
10
votes
1 answer

Draw text on image using Qt

I want to draw text on an image. I use this code, but I do not see any text on the image. void ImageSaver::save(const QString &path) const { QImage image(img_); QPainter p(&image); p.setPen(QPen(Qt::red)); p.setFont(QFont("Times",…
neda
  • 329
  • 1
  • 4
  • 15
1
2 3
22 23