stroke

HTML5 canvas - opacity problem with a paint app

北战南征 提交于 2019-12-08 04:55:12
问题 I'm trying to program a paint application using Canvas. the way it works is by connection lines when the mouse is pressed. when the line is opaque it works well, but when I change the alpha parameter I get a problem. I tried two options: a. The path begins when the mouse is down for the first time and ends when the mouse is up again: every move of the mouse calls the stroke() function. because the line is transparent the beginning of the whole path will become opaque and the end won't,

Why doesn't Graphics2D.setStoke() work for Graphics2D.drawString?

折月煮酒 提交于 2019-12-08 03:28:08
问题 I want the string to have different width so that I set the stroke of Graphics2D and the code is here: import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class StrokeTest { public static void main(String[] args) { StrokeTest test = new StrokeTest(); test.createUI(); } public void createUI(){ JFrame frame = new JFrame(); frame.add(new MainPanel());

How to prevent ugly spikes in canvas font rendering?

一世执手 提交于 2019-12-07 14:41:04
问题 When I draw text in canvas, I get ugly spikes, like this: Try it here: http://jsfiddle.net/48m4B/ While for example in photoshop, I get this: The code is just a classic strokeText: ctx.font = '20px Arial'; ctx.lineWidth = 15; ctx.strokeStyle = '#fff'; ctx.strokeText('How to prevent ugly spikes?'); If it isn't possible to fix this, is there any workaround? 回答1: Try to set line join to: ctx.lineJoin = 'round'; you can also adjust the miter limit: ctx.miterLimit = 2; Modified working fiddle 来源:

clear line on HTML5 Canvas

无人久伴 提交于 2019-12-07 06:12:15
问题 Is there a way to unstroke a line? On my canvas I have a line with opacity 0.5, and width of 20 pixels, let's say. Now I want to to make it longer, means to draw another line right out of the old one. when doing that, the matching points between the old and the new lines become less transparent (because they're made of two lines now). so I want to unstroke the old line and then stroke the new one. how can I do it? thanks 回答1: How you draw to a canvas is strictly defined by the API, but how it

HTML5 Canvas stroke not anti-aliased

。_饼干妹妹 提交于 2019-12-07 04:04:02
问题 I'm just trying to make a circle with a thick anti-aliased stroke in canvas. The circle gets drawn as expected, but the edges of the stroke are very jaggy. I keep reading that Chrome forces anti-aliasing, so not sure what to do... Fiddle: http://jsfiddle.net/nipponese/hWsxw/ HTML <div id="main"> <canvas id="myCanvas" width="400" height="400" style="border: 1px solid #000"></canvas> <div id="counter" style="height: 100px; width: 100px; border: 1px solid #000"> </div> </div> The JS + jQuery

Why doesn't Graphics2D.setStoke() work for Graphics2D.drawString?

耗尽温柔 提交于 2019-12-06 15:51:49
I want the string to have different width so that I set the stroke of Graphics2D and the code is here: import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class StrokeTest { public static void main(String[] args) { StrokeTest test = new StrokeTest(); test.createUI(); } public void createUI(){ JFrame frame = new JFrame(); frame.add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } @SuppressWarnings("serial")

kCGTextStroke's Fill and Stroke aren't positioned correctly

让人想犯罪 __ 提交于 2019-12-06 09:23:06
So I'm using the code below to apply a stroke (and fill) to text in a UILabel , and it's coming out like the image below. The stroke is heavier on one side than the other (look at the top of the letters compared to the bottom, and the right compared to the left. The period at the end makes it very noticeable, too, looks like a googly eye). I've not got any shadowing turned on at all, so I don't think it's the shadow interfering with the stroke. What could be causing this? - (void) drawTextInRect: (CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetTextDrawingMode(c,

How to prevent ugly spikes in canvas font rendering?

北城以北 提交于 2019-12-05 21:07:28
When I draw text in canvas, I get ugly spikes, like this: Try it here: http://jsfiddle.net/48m4B/ While for example in photoshop, I get this: The code is just a classic strokeText: ctx.font = '20px Arial'; ctx.lineWidth = 15; ctx.strokeStyle = '#fff'; ctx.strokeText('How to prevent ugly spikes?'); If it isn't possible to fix this, is there any workaround? Try to set line join to: ctx.lineJoin = 'round'; you can also adjust the miter limit: ctx.miterLimit = 2; Modified working fiddle 来源: https://stackoverflow.com/questions/19988099/how-to-prevent-ugly-spikes-in-canvas-font-rendering

HTML5 Canvas stroke not anti-aliased

烈酒焚心 提交于 2019-12-05 11:54:24
I'm just trying to make a circle with a thick anti-aliased stroke in canvas. The circle gets drawn as expected, but the edges of the stroke are very jaggy. I keep reading that Chrome forces anti-aliasing, so not sure what to do... Fiddle: http://jsfiddle.net/nipponese/hWsxw/ HTML <div id="main"> <canvas id="myCanvas" width="400" height="400" style="border: 1px solid #000"></canvas> <div id="counter" style="height: 100px; width: 100px; border: 1px solid #000"> </div> </div> The JS + jQuery <script> function calc(myVal) { var canvas = document.getElementById("myCanvas"); var ctx = canvas

AffineTransform without transforming Stroke?

大兔子大兔子 提交于 2019-12-05 01:35:56
When using the Graphics2D scale() function with two different parameters (scaling by different ratios in x- and y-direction), everything drawn later on this Graphics2D object is scaled too. This has the strange effect that lines drawn in one direction are thicker than those in another direction. The following program produces this effect, it shows this window: public class StrokeExample extends JPanel { public void paintComponent(Graphics context) { super.paintComponent(context); Graphics2D g = (Graphics2D)context.create(); g.setStroke(new BasicStroke(0.2f)); int height = getHeight(); int