[Cropper] Color problem (negative-like)

UI Components for JSF
Post Reply
vtomic85
Posts: 2
Joined: 07 May 2014, 16:47

17 Feb 2015, 16:42

Hi,
I have encountered the following problem with cropper. I tried to crop a PNG file (downloaded from the Internet), and I got the following result:
Image
So far, so good... Then I found the same image on the Internet, but didn't save it the usual way (Right click->Save image as), but instead I used Windows' Snipping tool to take a snapshot of it and then I saved it as a new PNG file. When I tried to crop the new file, here's what I got:
Image
It looks kinda negative.
I also tried to open the original downloaded image, then use a snipping tool on it, and when I tried to crop the new snipped image, I got the same (bad looking) result.
So it looks to me that for some reason Cropper isn't working well with the PNGs that were made using the Snipping tool. Does anybody have an idea what could be the problem?
Btw, it works well with all the JPG files I have tried so far...
Here's my code:

imageCropper.xhtml:

Code: Select all

<p:imageCropper value="#{cropperView.croppedImage}" image="#{cropperView.imgPath}" initialCoords="0,0,100,100" />
<p:graphicImage id="cropped" name="img/crop/#{cropperView.newImageName}.jpg" />
<p:commandButton value="Crop" action="#{cropperView.crop}" update="cropped msgs" icon="ui-icon-scissors"/>
CropperView.java:

Code: Select all

public void crop() {
        if (croppedImage == null) {
            return;
        }
        setNewImageName(getRandomImageName());
        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        String newFileName = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "img"
                + File.separator + "crop" + File.separator + getNewImageName() + ".jpg";
        FileImageOutputStream imageOutput;
        try {
            imageOutput = new FileImageOutputStream(new File(newFileName));
            imageOutput.write(croppedImage.getBytes(), 0, croppedImage.getBytes().length);
            imageOutput.close();
        } catch (Exception e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Cropping failed."));
        }
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Success", "Cropping finished."));
    }
---
I use:
Mojarra 2.2.4
PrimeFaces 4.0
Apache Tomcat 8.0.3.0

Lucasdm
Posts: 1
Joined: 31 Aug 2013, 00:25

23 Apr 2015, 16:01

Hi,
I have the same problem but with jpg images. I get image by Primefaces photoCam, save od hdd ant then user imageCropper. The result image is negative.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 47 guests