xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roy Hollinger <royh...@prologic-inc.com>
Subject Re: Image Map
Date Tue, 13 Dec 2005 18:19:16 GMT
This is quite possible.

Batik contains a few conversion (transform) methods to convert to png, jpeg, 
and (I believe) tiff.

Look in this area: org.apache.batik.transcoder.image.PNGTranscoder.

You might be able to use this:
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;

import com.prologic.symbologyserver.Utilities;

/**
 * @author royholl
 * 
 * @class PlPNGTranscoder
 * This extends the Apache PNGTranscoder and let's us crop the image before it
 * is written.
 */

public class pLPNGTranscoder extends PNGTranscoder
{
    /**
     * Writes the specified image to the specified output.
     * This is called by transcoder.transcode() to enact the writing to the
     * TranscodeOutput (normally a file, BufferedOutputStream or 
ByteOutputStream)
     * Calls superclass after image size has been fixed.
     * @param img the image to write
     * @param output the output where to store the image
     * @exception TranscoderException if an error occurred while storing the 
image
     */
    public void writeImage(BufferedImage img, TranscoderOutput output)
    	throws TranscoderException {

        Rectangle newRect = Utilities.GetSize(img, img.getWidth(), 
img.getHeight());
        BufferedImage img2 = img.getSubimage(0, 0, newRect.width, 
newRect.height);
        super.writeImage(img2, output);
    }


    public PlPNGTranscoder()
    {
        super();
    }
    
}


And a conversion method of:

    public IconReturnCore convertSVGIcon(SVGDocument svgData, int 
innerIconWidth)
    	throws Exception
    {
        IconReturnCore result = new IconReturnCore();
        if(pngTranscoder == null) pngTranscoder = new PlPNGTranscoder();
        
        TranscoderInput transcoderInput = new TranscoderInput(svgData);
        ByteArrayOutputStream ostream = null;
        try {
            ostream = new ByteArrayOutputStream();
            TranscoderOutput output = new TranscoderOutput(ostream);
            pngTranscoder.transcode(transcoderInput, output);
            ostream.flush();
            ostream.close();
            // This will put the byte[] in the IconReturnCore!
            result.setData(ostream.toByteArray());
        } catch (Exception ex) {
            result.getErrors().addError(
                    new ErrorItem (SymbolConstants.errorCodeConversionError,
                    "PNGConverter conversion error"));
            throw ex;
        }
        return result;
    }

This  works in 1.5 and 1.6.

On Tuesday 13 December 2005 12:58 pm, Peter Sparkes wrote:
> Hi
>
> Is it possible when using Batik to convert SVG to png to produce an HTML
> image map using "a" elements in the SVG.
>
> Thank you
>
> Peter Sparkes
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

-- 
Roy Hollinger
Senior Software Engineer
ProLogic, Inc.
royholl@prologic-inc.com


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message