java - Alternative(s) of converting Canvas to WritableImage -
i'm developing application needs lot of comparing image data in javafx. comparing, need to rgb data of pixels in images. let's picture need compare picture1 , picture2. picture1 input picture selected user. picture2 drawing make programmatically.
afaik, way rgb data per pixel in javafx pixelreader
of image
. it's fine picture1 since it's input. need drawing on picture2 , picture2 canvas
(i draw polygons on picture2 , because drawing pixel pixel pixelwriter bit complicated imo) , doesn't have pixelreader
or similar functionality. solution follows:
- read input image , make picture1
- make canvas , drawing
- attach canvas scene
- make snapshot of scene , make writableimage (picture2)
- compare picture1 , picture2
so have method like:
public static writableimage makedrawableimage(canvas in) { anchorpane root = new anchorpane(in); writableimage out = new writableimage((int)in.getwidth(), (int)in.getheight()); scene sc = new scene(root, in.getwidth(), in.getheight()); out = in.snapshot(null, null); return out; }
however takes long time snapshot finish. value of out
never gets assigned. don't know did wrong.
is there alternative convert canvas
image
or writableimage
? or maybe there library drawing of polygons easier pixelwriter
?
please soft on me. first question on stack overflow , i'm not real programmer nor student. code hobby.
so, in advance. cheers.
you can create snapshot of canvas method:
public static writableimage pixelscaleawarecanvassnapshot(canvas canvas, double pixelscale) { writableimage writableimage = new writableimage((int)math.rint(pixelscale*canvas.getwidth()), (int)math.rint(pixelscale*canvas.getheight())); snapshotparameters spa = new snapshotparameters(); spa.settransform(transform.scale(pixelscale, pixelscale)); return canvas.snapshot(spa, writableimage); }
the pixel scale 1.0 unless have hidpi screen.
Comments
Post a Comment