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.48k
    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:

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

    Call the function on defining the cropped image

    1. $('.cropbox').Jcrop({
    2. trueSize: [width, height],
    3. onSelect : function setCoordinates(c) {
    4. $('#x').val(frm.x);
    5. $('#y').val(frm.y);
    6. $('#w').val(frm.w);
    7. $('#xh).val(frm.h);
    8. }
    9. });

    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:

    1. BufferedImage originalImgage = ImageIO.read(new File("path of original image"));
    2. 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
Reset Password
Fill out the form below and reset your password: