Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

javascript - How to display node canvas on remote computer on my local desktop?

I'm very new with running anything in node. I'm trying to install it and display a canvas on my local desktop. About my environment:

I usually do development on my linux box, logged in remotely from my Win7 desktop using cygwin-X to display graphical output. For example I usually run 'gvim' on linux which displays on my Windows desktop. My linux box is headless, so any graphics it displays comes to my Windows desktop. Even OpenGL output like 'glxspheres' will run at the refresh rate of my desktop (set to one-half the sync rate, or 30FPS) using the indirect context.

However, when I run some trivial examples to try to open a canvas, nothing shows up on my display. Normally, any graphical output run on the server opens a window on my desktop, but either I'm not opening the canvas correctly, or its not displaying where I want it to.

I just changed it a simpler program and now the program runs for about 1.5s and then exits w/no apparent output and 100% cpu usage. To run it, I'm using "node ".

My primitive test prog looks like:

  const { createCanvas, loadImage } = require('canvas')
  const canvas = createCanvas(200, 200)
  const ctx = canvas.getContext('2d')
   
  ctx.font = '12px "Comic Sans"'
  ctx.rotate(0.1)
  ctx.fillText('Comic Sans is cute!', 50, 100)
   
  var text = ctx.measureText('Comic Sans is cute!')
  ctx.strokeStyle = 'rgba(0,0,0,0.5)'
  ctx.beginPath()
  ctx.lineTo(50, 102)
  ctx.lineTo(50 + text.width, 102)
  ctx.stroke()

I also tried the trivial example at https://flaviocopes.com/canvas-node-generate-image/ that I came across in a G-search:

  const { createCanvas } = require('canvas')
  const width = 1200
  const height = 600 
  const canvas = createCanvas(width, height)
  const context = canvas.getContext('2d')
  context.fillStyle = '#fff'
  context.fillRect(0, 0, width, height)

In the pictures on that page, it shows a black canvas that seems like it should be showing at this point.

I tried pasting the above into node interactively, as well as putting it in a file and trying to run it with 'node ', but still nothing.

My DISPLAY is set (it's always set when I login to my server) -- and besides a few gvim windows have 2 windows showing some server metrics (disk/net/cpu, etc).

Should what I am doing be opening a canvas window for me to "play" in? If that's right, then how might I get it to display? It can't be displaying on the server, there's no GUI (it has a text-console display), but I wouldn't expect it to come out there.

Ideas? I feel dumb asking such a basic question here, but if not here, where? (sigh)

question from:https://stackoverflow.com/questions/65878416/how-to-display-node-canvas-on-remote-computer-on-my-local-desktop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...