custom-painting

dart/flutter: CustomPaint updates at a lower rate than ValueNotifier's value update

旧街凉风 提交于 2020-07-23 07:50:07
问题 I use dart FFI to retrieve data from native side, and show the data with flutter CustomPaint . I use ValueNotifier to control CustomPaint repaint. Code: Poll data at a rate With a state class, I poll data from native side periodically, and assign it to the ValueNotifier . class _ColorViewState extends State<ColorView> { ValueNotifier<NativeColor> _notifier; Timer _pollTimer; @override void initState() { // TODO: implement initState super.initState(); ffiInit(); // initialize notifier

dart/flutter: CustomPaint updates at a lower rate than ValueNotifier's value update

风格不统一 提交于 2020-07-23 07:49:11
问题 I use dart FFI to retrieve data from native side, and show the data with flutter CustomPaint . I use ValueNotifier to control CustomPaint repaint. Code: Poll data at a rate With a state class, I poll data from native side periodically, and assign it to the ValueNotifier . class _ColorViewState extends State<ColorView> { ValueNotifier<NativeColor> _notifier; Timer _pollTimer; @override void initState() { // TODO: implement initState super.initState(); ffiInit(); // initialize notifier

How to crop the png image and remove its unused space using Canvas in flutter?

坚强是说给别人听的谎言 提交于 2020-03-04 20:48:07
问题 This attachment is from the rendered canvas image which is saved locally via canvas. In image I have drawn the square box which I want to render in canvas and save locally without left and right extra spaces . I just want to save the square box and remove that unnecessary space of PNG-image. So, how to do this? widget-source-code: return CustomPaint( painter: PngImageCropper(image: image), ); PngImageCropper-code class PngImageCropper extends CustomPainter { PngImageCropper({ this.image, });

Flutter: How to paint an Icon on Canvas?

僤鯓⒐⒋嵵緔 提交于 2020-01-24 20:37:08
问题 I'm using a CustomPainter to draw in Flutter like this: @override void paint(Canvas canvas, Size size) { canvas.drawRect(...); canvas.drawImage(...); ... } How to draw an Icon on canvas ? 回答1: Create a Paragraph containing the code point in the correct font, style it as needed, then draw it. final icon = Icons.add; var builder = ui.ParagraphBuilder(ui.ParagraphStyle( fontFamily: icon.fontFamily, )) ..addText(String.fromCharCode(icon.codePoint)); var para = builder.build(); para.layout(const

Flutter: How to paint an Icon on Canvas?

断了今生、忘了曾经 提交于 2020-01-24 20:37:05
问题 I'm using a CustomPainter to draw in Flutter like this: @override void paint(Canvas canvas, Size size) { canvas.drawRect(...); canvas.drawImage(...); ... } How to draw an Icon on canvas ? 回答1: Create a Paragraph containing the code point in the correct font, style it as needed, then draw it. final icon = Icons.add; var builder = ui.ParagraphBuilder(ui.ParagraphStyle( fontFamily: icon.fontFamily, )) ..addText(String.fromCharCode(icon.codePoint)); var para = builder.build(); para.layout(const

drawingPanel color change with displacement

烈酒焚心 提交于 2020-01-19 17:43:06
问题 I'm using JGrasp, and in drawingPanel , I'm trying to create a ball that changes colors as it moves across the screen. Right now, I've got: for (int i = 10; i<=i; i++) { Color c = new Color(i*i, 0, 0); pen.setColor(c); My full simplified code is: import java.awt.*; import java.util.*; import java.awt.Color; public class BallSample { public static final int SIZE = 30; public static final int HALF = SIZE / 2; public static void main(String[] args) { Scanner console = new Scanner(System.in);

Graphics2D line and shape drawing issues (rendered in wrong place)

老子叫甜甜 提交于 2020-01-05 04:08:47
问题 I've drawn three arrows using Graphics2D. three drawLine s draw(Shape) fill(Shape) Here's what it looks like enlarged: I cannot understand two things: Why is the filled one smaller and shifted? Secondly, why do arrows 1. and 3. look different? Both consist of 3 antialiased lines. Shouldn't they (potentially) differ only in vertices? Here's the whole code: import javax.swing.*; import java.awt.*; public class ShapeTest extends JPanel { public static void main(String [] args) { JFrame frame =

Drawing shapes on a JForm java

有些话、适合烂在心里 提交于 2019-12-18 09:44:08
问题 I have created this code that is supposed to draw certain things when I selected a radio button on a JForm, I have used NetBeans to create the GUI. When I select a radio button nothing happens. I have been trying to figure out what's wrong for a while but I still cannot find a solution that's why I came here. If anyone could spot a mistake I would be thankful. public class DrawShapesGUI extends javax.swing.JFrame { private int figureID; public DrawShapesGUI() { initComponents(); repaint(); }

Draw lines for every mouse click and stop drawing when double clicked

醉酒当歌 提交于 2019-12-18 09:31:55
问题 I have to draw line as the mouse moves, after the mouse click, the line should be continued to draw until double clicked. Say point A, point B and point C. when mouse clicked at point A, the drawing of line should be started. when mouse is clicked on point B, the prev line should be there along with that new line should be started drawing from point B unless double clicked. Should be the same for point C and so on until the mouse is double clicked. After some research, I have written below