Right way to use a SnapshotView

135 views
Skip to first unread message

Robson SD

unread,
Dec 8, 2014, 10:39:36 AM12/8/14
to control...@googlegroups.com
Hey guys, all right?...

I need your help.

I'm trying to use the SnapshotView to create a crop area over an ImageView, but in doc the sample code is very simple and doesn't works...
I had to use the controlsfx-sampler but in my job the network have proxy and this fuck in everything, because this the sampler,also, doesn't works.

What's the best way to do this? 

Thanks

Nicolai Parlog

unread,
Dec 9, 2014, 3:11:38 PM12/9/14
to control...@googlegroups.com
 Hi Robson,

I'm the main author of the SnapshotView. I recommend against using the version currently available in ControlsFX because it contains bugs to the point where it is almost unusable (sorry for that). I did a big overhaul of the whole control which breaks the API as it exists now. Those changes are in the progress of being merged and I hope they make it into the next release.

If you can absolutely not wait until then, I might be able to cobble together a pre-release stand-alone jar (assuming there are no license issues I am not aware of).

 so long ... Nicolai

Robson SD

unread,
Dec 10, 2014, 7:05:53 AM12/10/14
to control...@googlegroups.com
Thanks for reply, just let me try to show you my war :) ... my scenario is:

I have a ImageView Javafx component with an image.
I need to create a rectangle (selection area) to crop, like is showing in controlsfx showcase.
After this I need to press one button or other component to do a crop in ImageView. I'm using JAI in background (model) to make a crop on the image real size, but I want just to crop a simple ImageView for understand the work way of this component SnapshopView.
I had trying to see and understand the source code in the class HelloSnapshopView.java inside .jar of ControlsFX (controlsfx-8.20.8) but just the code don't make sense for me...
The events and listeners to make possible the creation of retangle like too resize it and move it over the ImageView is built in Snapshop component? How can I do a simple and complete example to create and crop an image with snaphopView? ... or only in next release like you said?
Anyway I thank you for this component, it's very usefull, I'm very anxious to use it in my projects :)

Hugs

Nicolai Parlog

unread,
Dec 10, 2014, 3:00:44 PM12/10/14
to control...@googlegroups.com
> After this I need to press one button or other component to do a crop in ImageView.
> I'm using JAI in background (model) to make a crop on the image real size, but I want
> just to crop a simple ImageView for understand the work way of this component
> SnapshopView.
I am not really sure, whether I understood a 100%... So you want to select an area of an image and then crop the image to that selection, right?
The SnapshotView is the right control for the first part of that. It let's you make that selection. For the second part (cropping the image) you can use 'SnapshotView.createSnapshot()' to get an image of the selected area or get the selected area's coordiantes with 'SnapshotView.getSelection()' and do the cropping yourself. If you want to display the cropped image you have to write it back to the 'ImageView' contained in the 'SnapshotView'.


> The events and listeners to make possible the creation of retangle like too resize it
> and move it over the ImageView is built in Snapshop component?
This is split between several classes. Important ones are 'SnapshotViewBehavior and 'SnapshotViewSkin' but all of the actual Rectangle2D-math is pushed onto separate code in the package 'impl.org.controlsfx.tools.rectangle'. While it is well written and documented (at least I think so) this is no easy read. I also think there is no immediate use in trying to understand that code.


> How can I do a simple and complete example to create and crop an image with
> snaphopView? ... or only in next release like you said?
Waiting for the next release (and hoping that the control makes it) would be my recommendation. If you can't wait that long, you should be able to get it to work for images with the version that is out there. But beware: (a) you might have to put up with some buggy behavior and (b) when the new version is released, you have to go over your code and change things.

If that is ok for you, you should get it to work. I just created a small demo project over at GitHub. If you're using Eclipse, it should work out of the box. The important part is this method:

private static Parent createRoot() {
   
GridPane rootPane = new GridPane();
   
ImageView imageView = new ImageView(IMAGE_PATH);
   
SnapshotView snapshotView = new SnapshotView(imageView);
    rootPane
.add(snapshotView, 0, 0); return rootPane;
}

It creates an 'ImageView' which is then handed to the 'SnapshitView'. To display another image jsut call 'imageView.setImage'.

 I hope this helps
 Nicolai
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
     
     
       
       
        private static Parent createRoot() {
               GridPane rootPane = new GridPane();
               ImageView imageView = new ImageView(IMAGE_PATH);
               SnapshotView snapshotView = new SnapshotView(imageView);
               rootPane.add(snapshotView, 0, 0);
               return rootPane;
       }



Robson SD

unread,
Dec 11, 2014, 6:32:41 AM12/11/14
to control...@googlegroups.com
Nicolai, you rock!!
Worked like a charm! thks so much!

Nicolai Parlog

unread,
Dec 11, 2014, 1:45:54 PM12/11/14
to control...@googlegroups.com
Cool. Happy to help. :)
Reply all
Reply to author
Forward
0 new messages