0
I’m trying to cut an image with the component imageCropper of Primefaces, but in the implementations I performed it only gives conversion error, and when not, the object croppedImage that Primefaces implements comes null. Note: The context of my web application is https. In my tests when I put an image of any web context https it also gives error. I already put converter and everything, but the converter it does not call! Please, I need help!
Here is an excerpt from the code of the page:
<div class="Container100 Responsive100 ContainerIndent">
                    <p:fileUpload auto="true" fileUploadListener="#{fileUploadController.uploadBase64}"
                                  sizeLimit="1000000" fileLimitMessage="Atenção! Por favor, Anexe apenas uma foto!"
                                  multiple="false"
                                  label="Selecione uma foto"
                                  allowTypes="/(\.|\/)(jpg|jpeg|png)$/"
                                  update="imagemDeCorte2"/>
                </div>
                <h:panelGrid columns="2">
                    <p:imageCropper id="imagemDeCorte2" value="#{fileUploadController.croppedImage}"
                                    image="#{fileUploadController.nomeImagemB64}"
                                    rendered="#{fileUploadController.nomeImagemB64}"
                                    initialCoords="0,0,354,472"
                                    aspectRatio="0.75"/>
                </h:panelGrid>
                <p:commandButton value="Crop" action="#{fileUploadController.crop}"
                                 icon="ui-icon-scissors"/>
Java code:
 public void uploadBase64(FileUploadEvent event) throws IOException {
    arquivoFoto = event.getFile();
    String mimeType = FileUtils.detectMimeType(arquivoFoto.getContents());
    if (!arquivoFoto.getContentType().equals(mimeType)) {
        throw new IOException("Tipo do arquivo está errado: " + mimeType);
    }
    formatoFoto = arquivoFoto.getContentType();
    nomeFoto = arquivoFoto.getFileName();
    imageAsByteFoto = ByteBuffer.allocate(new Long(arquivoFoto.getSize()).intValue());
    try {
        InputStream is = arquivoFoto.getInputstream();
        //redimensiona a imagem
        BufferedImage img = ImageIO.read(is);
        BufferedImage scaledImg = Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_TO_HEIGHT, 450, 600);
        arquivoFoto.getInputstream().read(imageAsByteFoto.array());
        ImagemBase64 ib4 = new ImagemBase64();
        String base64AsString = new String(Base64.encode(imageAsByteFoto.array()));
        ib4.setB64(base64AsString);
        ib4.setFormato(formatoFoto);
        ib4.setNome(nomeFoto);
        nomeImagemB64 = ib4.getSrc();
        nomeImagemB642 = ib4.getSrc();
        imagemFile = new File("imagemCortada.".concat(FilenameUtils.getExtension(nomeFoto)));
        org.apache.commons.io.FileUtils.writeByteArrayToFile(imagemFile, imageAsByteFoto.array());
        imagemCarregada = Base64.decode(ib4.getSrc());
        reload();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
The code you posted does not show the Crop method, only the upload method.
– Marcus Martins
Check this other question, it might help: http://answall.com/questions/4938/salvar-imagem-cropped
– Marcus Martins
You can also try Jcrop http://deepliquid.com/content/Jcrop.html
– Marcus Martins