Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Image Crop Using Java and Jquery Crop (Jcrop)

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1.47k
    Comment on it

    FrontEnd:

    Include jquery.Jcrop.css, jquery.Jcrop.js and jquery.Jcrop.min.js

    Open an image in a div with a form. Take 4 hidden input fields:

    <input type="hidden" id="x" name="x" /> // x coordinate of the image
    <input type="hidden" id="y" name="y" /> // y coordinate of the image
    <input type="hidden" id="w" name="w" /> // width of the specified rectangular region
    <input type="hidden" id="h" name="h" /> // height of the specified rectangular region
    

    Call the function on defining the cropped image

    $('.cropbox').Jcrop({
            trueSize: [width, height],
            onSelect :  function setCoordinates(c) {
                      $('#x').val(frm.x);
                      $('#y').val(frm.y);
                      $('#w').val(frm.w);
                      $('#xh).val(frm.h);
                }
            });
    

    Here trueSize: [width, height] will help in maintaining the original height, width of the image (since on UI we may need to show the image in an small size)

    BackEnd:

    BufferedImage originalImgage = ImageIO.read(new File("path of original image"));
    BufferedImage SubImage = originalImgage.getSubimage(x, y, w, h);
    

    Save subimage to DB.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: