BufferedImage thumbnail = new BufferedImage(thumb.getWidth(null), thumb .getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2d = thumbnail.createGraphics(); g2d.drawImage(buf, 0, 0, (int) xsize, (int) ysize, null);
    public InputStream getDestinationStream(InputStream source)            throws Exception    {        // read in bitstream's image        BufferedImage buf = ImageIO.read(source);        // get config params        float xmax = (float) ConfigurationManager                .getIntProperty("thumbnail.maxwidth");        float ymax = (float) ConfigurationManager                .getIntProperty("thumbnail.maxheight");        Image thumb = null;        // now get the image dimensions        float xsize = (float) buf.getWidth(null);        float ysize = (float) buf.getHeight(null);        // if verbose flag is set, print out dimensions        // to STDOUT        if (MediaFilterManager.isVerbose)        {            System.out.println("original size: " + xsize + "," + ysize);        }        // scale by x first if needed        if (xsize > xmax)        {            // calculate scaling factor so that xsize * scale = new size (max)            float scale_factor = xmax / xsize;            // if verbose flag is set, print out extracted text            // to STDOUT            if (MediaFilterManager.isVerbose)            {                System.out.println("x scale factor: " + scale_factor);            }            // now reduce x size            // and y size            xsize = xsize * scale_factor;            ysize = ysize * scale_factor;            // if verbose flag is set, print out extracted text            // to STDOUT            if (MediaFilterManager.isVerbose)            {                System.out.println("new size: " + xsize + "," + ysize);            }        }        // scale by y if needed        if (ysize > ymax)        {            float scale_factor = ymax / ysize;            // now reduce x size            // and y size            xsize = xsize * scale_factor;            ysize = ysize * scale_factor;        }        // if verbose flag is set, print details to STDOUT        if (MediaFilterManager.isVerbose)        {            System.out.println("thumbnail size: " + xsize + ", " + ysize);        }        thumb = buf.getScaledInstance((int) xsize, (int) ysize,                Image.SCALE_SMOOTH);        // create a BufferedImage to draw this image into...        BufferedImage thumbnail = new BufferedImage(thumb.getWidth(null), thumb                .getHeight(null), BufferedImage.TYPE_3BYTE_BGR);        Graphics2D g2d = thumbnail.createGraphics();        // draw thumb into thumbnail        g2d.drawImage(thumb, null, null);        // now create an input stream and return it        // there has got to be a better way than this!        ByteArrayOutputStream baos = new ByteArrayOutputStream();        ImageIO.write(thumbnail, "jpeg", baos);        // now get the array        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());        return bais; // will this work? or will the byte array be out of scope?    }