0

I have a canvas of screen size where I draw certain shapes. Now I want to copy that shape (given relative x,y, width and height of the shape on the canvas) into new canvas. How do I do that?

For cropping, it may involve resizing/redrawing, in which case I will stick to copying approach.

Aung Khant
  • 324
  • 3
  • 14
  • As illustrated [here](https://stackoverflow.com/a/45685372/230513), there's nothing to copy until the `Canvas` is rendered; instead, consider drawing into a `BufferedImage`. – trashgod Jan 20 '19 at 16:54
  • That kinda sucks. I thought of drawing an Image to buffer, but never tried it before. I was trying to simulate the following behavior: Imagine you have a transparent stage window covering the entire screen. I would draw rectangular dotted figure anywhere on screen. Once I've drawn, I would like to resize stage window to fit the drawing. – Aung Khant Jan 20 '19 at 18:35
  • You could do that using a `Rectangle`, rather than a `Canvas`. Though you'd likely need to use two different stages. – Slaw Jan 20 '19 at 19:56
  • You can also specify a suitable `BlendMode` in your `GraphicsContext` or `AlphaComposite` in your `BufferedImage` context. – trashgod Jan 20 '19 at 22:50

0 Answers0