Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6753035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:06:50+00:00 2026-05-26T13:06:50+00:00

I am trying to crop the image using JQuery Jcrop plugin with Java Stuff,

  • 0

I am trying to crop the image using JQuery Jcrop plugin with Java Stuff, but I am unable to get the correct result.

Jsp code:

<script type="text/javascript">
$(function () {
    $('#actualImage').Jcrop({
     setSelect: [0, 0, 268, 180],
     addClass: 'custom',
     bgColor: 'yellow',
     bgOpacity: .8,
     //sideHandles: true
     allowResize: false,
     allowSelect: false,
     onSelect: storeCoords
 });
});

function storeCoords(c) {

 jQuery('#X1').val(c.x);
 jQuery('#Y1').val(c.y); 
 jQuery('#X2').val(c.x2);
 jQuery('#Y2').val(c.y2); 
 jQuery('#W').val(c.w);
 jQuery('#H').val(c.h);
}

function cropPicture(){
    $.ajax({
        url: "cropPhoto.htm",
        type: "POST", 
        data :{
            x : $('input#X1').val(),
            y : $('input#Y1').val(),
            x2 : $('input#X2').val(),
            y2 : $('input#Y2').val(), 
            w : $('input#W').val(),
            h : $('input#H').val(),
            imageName : $('input#imageName').val()
        },
        success: function (data) { 
            window.location = 'photo.htm';
         }
}
</script>

Java code:

@RequestMapping(value = "cropPhoto.htm", method = RequestMethod.POST)
    public String cropPhoto(HttpServletRequest request,HttpServletResponse response,
            HttpSession session) throws IOException{
         int x1=Integer.parseInt(request.getParameter("x"));
         int y1=Integer.parseInt(request.getParameter("y"));
         int x2=Integer.parseInt(request.getParameter("x2"));
         int y2=Integer.parseInt(request.getParameter("y2"));
         int w=Integer.parseInt(request.getParameter("w"));
         int h=Integer.parseInt(request.getParameter("h"));
         System.out.println(x1+" "+y1+" "+x2+" "+y2+" "+w+" "+" "+h);

         String image = request.getParameter("imageName");
         System.out.println("imageName"+image);

         String sourcePath =   request.getRealPath("") + "/FreeTemp/";
         String serverPath = sourcePath + session.getAttribute("uploadFile");
         serverPath = serverPath.replace("\\", "/");
         System.out.println(serverPath);

         BufferedImage bi = ImageIO.read(new File(serverPath));

         BufferedImage out = bi.getSubimage(x1, y1, w, h);

         ImageIO.write(out,"jpg",new File(sourcePath + image));

         session.setAttribute("croppedImage", image);

         PrintWriter writer = response.getWriter();
         response.setContentType("text/html");

        return "redirect:/savephoto.htm";
    }

I am able to crop the photo, but the result is not correct. For example look at the following images:

Original Image with selection to crop
cropped image which is incorrect

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:06:50+00:00Added an answer on May 26, 2026 at 1:06 pm

    Yes i got the problem.I need to resize the image.So, i have done using the following code:

    public static BufferedImage resizeImage(BufferedImage originalImage, int type){
            BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
            Graphics2D g = resizedImage.createGraphics();
            g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
            g.dispose();
    
            return resizedImage;
        }
    

    Now i am able to get the cropped image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop image crop using JQuery. I use ajax to upload the
I'm simply trying to crop a JPEG image (no scaling) using PHP. Here is
i am trying to crop a gif image using the libMagick.so library. ./convert --version
I am trying to crop and image using PHP and the GD library and
I am trying to do a simple crop of an image, but for some
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
i got a jquery upload and crop script and i am trying to use
I'm trying to crop an image and then paste the cropped image into the
I am trying to crop an image. I have found multiple ways to do
I'm trying to convert a fetched image from JPG to PNG using RMagick, resize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.