Page 1 of 2

[solved]imagerotateandresize

Posted: 14 May 2012, 08:54
by azadeh
hi
i'm new in primefaces extension
i use primefaces extension for rotate and resize my image. my image is a picture file from my system
but i want to save this image after resize or rotate on same image in same location .
i don't know how to do it
please help

Re: imagerotateandresize

Posted: 14 May 2012, 09:30
by tandraschko
You can't without more code :)
You must catch the resize and rotate events on server side and save the values in a viewScoped bean.
Then (if you click on a save button or else) you must rotate/resize your image via a java image api. We've done it via BufferedImage.

Re: imagerotateandresize

Posted: 14 May 2012, 10:02
by azadeh
thanks for your reply
can you give me an example with java code to do it??????
thanks

Re: imagerotateandresize

Posted: 14 May 2012, 11:11
by tandraschko
search for BufferedImage in google, it's easy.

Re: imagerotateandresize

Posted: 16 May 2012, 10:17
by azadeh
i searched in google and find many example
but i cant understand how to use it
for example in my xhtml page how call my servlet class that has buffredimage or
in my java class how get rotated or scaled image from xhtml page and .....
please help me
thanks

Re: imagerotateandresize

Posted: 16 May 2012, 10:30
by tandraschko

Code: Select all

<pe:imageRotateAndResize id="rotateAndResize" for="myImage" widgetVar="rotateAndResizeWidget">  
    <p:ajax event="rotate" listener="#{imageController.rotateListener}" update="growl"/>  
    <p:ajax event="resize" listener="#{imageController.resizeListener}" update="growl"/>  
</pe:imageRotateAndResize>  

<p:commandLink actionListener="#{imageController.saveImageToDisk}"/>

Code: Select all

@Named or @ManagedBean
@ViewScoped
public class ImageController implements Serializable {

    private int rotationDegree;
    private int height;
    private int width;

    public void rotateListener(final RotateEvent e) {  
        this.rotationDegree= e.getDegree();
    }  
  
    public void resizeListener(final ResizeEvent e) {  
       this.height = e.getHeight();
       this.width = e.getWidth();
    }  

   public void saveImageToDisk() {
      //load your iamge wiht bufferedImage
      //resize and rotate it with rotationDegree, height & width
      //save it

    }
}

Re: imagerotateandresize

Posted: 19 May 2012, 07:36
by azadeh
thanks for reply
but when click on scale button give me this error:
method not found: resizeListener(org.primefaces.extensions.event.ResizeEvent)
what is my problem???????

Re: imagerotateandresize

Posted: 19 May 2012, 11:35
by tandraschko
Don't know, please look at the showcase.

Re: imagerotateandresize

Posted: 19 May 2012, 13:14
by tandraschko
As i can see, it works in our app. Please check your bean and method signature. ResizeEvent must be from extensions, not from PF.

Re: imagerotateandresize

Posted: 20 May 2012, 05:49
by azadeh
yes that's right
thank you
i solved it with your help
i used pf istead of extension