draw

Measuring text width to be drawn on Canvas ( Android )

孤街浪徒 提交于 2019-11-28 16:26:38
Is there a method which returns the width ( in pixels ) of a text to be drawn on an Android canvas using the drawText() method according to the Paint used to draw it? Have you looked at android.graphics.Paint.measureText(String txt) ? hamid reza zavareh Paint paint = new Paint(); Rect bounds = new Rect(); int text_height = 0; int text_width = 0; paint.setTypeface(Typeface.DEFAULT);// your preference here paint.setTextSize(25);// have this the same as your text size String text = "Some random text"; paint.getTextBounds(text, 0, text.length(), bounds); text_height = bounds.height(); text_width =

Draw line animated

隐身守侯 提交于 2019-11-28 16:26:08
I want to have a line in the center of the screen and animate it like a snake This is step by step animation I want to make How can I do this? You can animate the end of the stroke of a path on a CAShapeLayer , e.g., weak var shapeLayer: CAShapeLayer? @IBAction func didTapButton(_ sender: Any) { // remove old shape layer if any self.shapeLayer?.removeFromSuperlayer() // create whatever path you want let path = UIBezierPath() path.move(to: CGPoint(x: 10, y: 50)) path.addLine(to: CGPoint(x: 200, y: 50)) path.addLine(to: CGPoint(x: 200, y: 240)) // create shape layer for that path let shapeLayer

How to make any view to draw to canvas?

孤街醉人 提交于 2019-11-28 15:21:32
问题 I have a short question: Suppose I have a (mutable) bitmap that I need to modify (add images, texts, etc...) . Instead of messing around with many special classes for drawing to the canvas (paint, canvas, matrices and so on), I was thinking why not use the built in classes of Android for this task and only if i need really customized operations i could still use the canvas ? So, for example, in order to show any kind of view (that has no parent, of course) on the bitmap, I could call the next

Why is my line not drawing?

青春壹個敷衍的年華 提交于 2019-11-28 14:50:23
So I have defined a mouseEventlistener and mousemotionListener to define points as so. protected Point elementPosition = null; public Point endPoint = null; public Axis tempAxis; public Graphics g; class MouseButtonHandler extends MouseAdapter { public void mousePressed(MouseEvent e) { if(e.getModifiers()==InputEvent.BUTTON1_MASK) { elementPosition =new Point(e.getX(), e.getY()) ; if(addType==YLABEL) { YDialog ydia = new YDialog(anApp); ydia.setVisible(true); value =(double) ydia.getValue(); ydia.dispose(); } } } public void mouseReleased(MouseEvent e) { } } class MouseMoveHandler extends

How to draw a rectangle around multiline text

纵然是瞬间 提交于 2019-11-28 14:43:00
I am trying to draw a rectangle around multiline text in iText. The user will be able to enter some lines of text. The font size of the text might be different and it can be formatted (bold, underlined...). I use this code to draw the text: ColumnText ct = new ColumnText(cb); Phrase phrase = new Phrase("Some String\nOther string etc...\n test"); ct.setSimpleColumn(myText......); ct.addElement(phrase); ct.go(); I know how to draw a rectangle, but I am not able to draw a rectangle outlining this text. It sounds as if you are missing only a single piece of the puzzle to meet your requirement.

How to draw multiple shapes on JComponent or Jpanel?

冷暖自知 提交于 2019-11-28 14:38:02
I'm trying to build Paint app and I doing something wrong in DrawingArea class. The problem is when I try to draw second shape , the first shape or figure is auto deleting so I need to some idea about how to solve this.All answers acceptable. THANKS FOR HELP. There is part of DrawingArea.class codes : @Override // GETTING FIRST (STARTING) COORDINATE WHEN THE MOUSE PRESSED public void mousePressed(MouseEvent e) { oldX = e.getX(); oldY = e.getY(); repaint(); } @Override // GETTING RELEASED COORDINATE TO DRAW LINE. public void mouseReleased(MouseEvent e) { lastX = e.getX(); lastY = e.getY();

Draw a semi ring - JavaFX

久未见 提交于 2019-11-28 13:35:02
I would like to know how to draw a semi circle in JavaFX. I tried to use Shape and QuadCurve but I couldn't make a perfect semicircle. Here is a picture of what I'm trying to draw : The picture you linked is actually a semi-ring. You can get it in JavaFX by drawing nested 2 arcs and some lines. But my preferred way is to use the Path . public class SemiDemo extends Application { @Override public void start(Stage primaryStage) { Group root = new Group(); root.getChildren().add(drawSemiRing(120, 120, 100, 50, Color.LIGHTGREEN, Color.DARKGREEN)); root.getChildren().add(drawSemiRing(350, 350, 200,

Java - draw a triangle [duplicate]

只谈情不闲聊 提交于 2019-11-28 13:20:47
问题 This question already has an answer here: Triangle Draw Method 7 answers Hey I know that it is simple to draw oval/rectangle and fill it using g.fillOval(30, 40, 20, 20); but how to draw a triangle? It would be the best if it would have random coordinates. 回答1: There are at least two basics ways you can achieve this, based on your needs. You could use Polygon or you could make use the 2D Graphics Shape API Which you might choose comes down to your requirements. Polygon requires you to know,

I want to draw custom shape like apple shape on UIView

独自空忆成欢 提交于 2019-11-28 11:49:25
I am trying to make Apple kind of shape for progressHUD. I have option to use .png Image but I cant because I have to fill the apple Shape with different colour depends of percentage status.. I am using UIView to draw this shape... I want suggestion how to draw apple kind of shape easily? And How we can fill half colour with different colour? I have option to use .png Image but I cant Yes, you can. — Get hold of some apple-shaped artwork. Use it as a mask - it punches a hole in a view. Now put another view behind it, with a color. Now the apple appears to be that color, because that color is

HTML / Java Script Canvas - how to draw an image between source and destination points?

…衆ロ難τιáo~ 提交于 2019-11-28 11:47:57
I've tried to use the drawImage function of the canvas. In the documentation ( http://msdn.microsoft.com/en-us/library/ie/ff975414(v=vs.85).aspx ) I thought the last two parameters are the destination point, but I guess it's not because it's not working. Is there a way to draw image between two points without rotate it or something like this? Thanks! context.drawImage( sourceImage, sourceX, sourceY, sourceWidthToClip, sourceHeightToClip, canvasX, canvasY, scaledWidth, scaledHeight ); In context.drawImage the first parameter is the source image. The next 4 parameters are the x,y,width & height