Questions tagged [drawtext]

314 questions
202
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,428
  • 2
  • 14
  • 25
95
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,455
  • 5
  • 23
  • 33
49
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,089
  • 1
  • 8
  • 21
34
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
  • 3,594
  • 5
  • 32
  • 42
28
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,126
  • 2
  • 17
  • 21
20
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
18
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
  • 241
  • 1
  • 4
  • 15
13
votes
5 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
  • 2,827
  • 6
  • 34
  • 49
12
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
  • 4,369
  • 10
  • 55
  • 116
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
  • 20,269
  • 17
  • 45
  • 90
11
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
  • 364,799
  • 232
  • 1,155
  • 1,198
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
7 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
  • 133
  • 1
  • 5
9
votes
2 answers

why my invoke of Canvas.drawText() just doesn't work

Hi all: I'm writing a class that inherit from TextView, and override its onDraw() method, but in the method, my invoke of canvas.drawText() doesn't seems to work, the code just like below: protected void onDraw(Canvas canvas) { //…
Wenlin.Wu
  • 730
  • 1
  • 8
  • 17
9
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
  • 319
  • 2
  • 13
1
2 3
20 21