1 Reply Latest reply: Nov 17, 2010 12:07 AM by Maxideon RSS

    JAI crop function

      Hello All,

      I am using JAI crop function with starting pixels, width and height. But starting pixels is not working. It is cropping the image always begginning from left side (0,0) to the given (width,height). You can find my code below. I am waiting for your responses.

      private static byte[] bin;
      public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException, ServletException {
           InputStream imageInputStream = new ByteArrayInputStream(bin);
                SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
                RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);

           ParameterBlock pb = getParameterBlockForImage(image);
      PlanarImage image = JAI.create("crop", pb);
           // save the image
                ByteArrayOutputStream stream = new ByteArrayOutputStream();

                JAI.create("encode", image, stream, "jpeg");

      bin = stream.toByteArray();
      OutputStream out = res.getOutputStream();
                out.write(bin, 0, bin.length);

      Thanks in advance

      Edited by: user1778624 on 08.Kas.2010 00:50
        • 1. Re: JAI crop function
          I don't think the crop function would arbitrarily ignore your (x,y). Are you sure your x and y are not 0? Prove to yourself that they're not by adding some System.out calls just before they get added to the parameter block.

          Also, I'm not familiar with the function getParameterBlockForImage(image)?