You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by he...@primushost.com on 2002/12/08 07:00:01 UTC

SVG --> static BufferedImage

Hello,

I'd just like to create a static BufferedImage from a SVG document, with
some ability to specify image size and zoom factor, much like this API
from librsvg from the GNOME 2.2 platform,

/**
 * rsvg_pixbuf_from_file_at_zoom_with_max:
 * @file_name: A file name
 * @x_zoom: The horizontal zoom factor
 * @y_zoom: The vertical zoom factor
 * @max_width: The requested max width
 * @max_height: The requested max height
 * @error: return location for errors
 *
 * Loads a new #GdkPixbuf from @file_name and returns it.  This pixbuf is scaled
 * from the size indicated by the file by a factor of @x_zoom and @y_zoom. If the
 * resulting pixbuf would be larger than max_width/max_heigh it is uniformly scaled
 * down to fit in that rectangle.\302\240The caller must assume the reference to the
 * returned pixbuf. If an error occurred, @error is set and %NULL is returned.
 *
 * Return value: A newly allocated #GdkPixbuf, or %NULL
 **/

GdkPixbuf*
rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
                                        double x_zoom,
                                        double y_zoom,
                                        gint max_width,
                                        gint max_height,
                                        GError **error);


I tried to pull what I need from the swing components (JSVGCanvas and
superclasses) and from the transcoder package, but I can't follow all of
what's going on under the hood.  Is there something that I'm missing?

   michael



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


Re: SVG --> static BufferedImage

Posted by "Michael L. Heuer" <he...@primushost.com>.
Hello Vincent,

Thank you for your reply.  I wrote this class which abuses the spirit of
the transcoding api a bit but does what I need

import java.awt.image.BufferedImage;

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

class BufferedImageTranscoder
    extends ImageTranscoder
{
    private BufferedImage image;

    public BufferedImage createImage(int width, int height)
    {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    }
    public void writeImage(BufferedImage image, TranscoderOutput output)
        throws TranscoderException
    {
	// ignore output parameter

        this.image = image;
    }
    public BufferedImage getImage()
    {
        return image;
    }
}

   michael


On Mon, 9 Dec 2002, Vincent Hardy wrote:

> Hello Michael,
>
> There is support for what you are looking for. First, there is a command
> line application to generate rasters from SVG content:
>
> http://xml.apache.org/batik/svgrasterizer.html
>
> and there is a generic transcoding API:
>
> http://xml.apache.org/batik/rasterizerTutorial.html
>
> Vincetn.
>
> heuermh@primushost.com wrote:
> > Hello,
> >
> > I'd just like to create a static BufferedImage from a SVG document, with
> > some ability to specify image size and zoom factor, much like this API
> > from librsvg from the GNOME 2.2 platform,
> >
> > /**
> >  * rsvg_pixbuf_from_file_at_zoom_with_max:
> >  * @file_name: A file name
> >  * @x_zoom: The horizontal zoom factor
> >  * @y_zoom: The vertical zoom factor
> >  * @max_width: The requested max width
> >  * @max_height: The requested max height
> >  * @error: return location for errors
> >  *
> >  * Loads a new #GdkPixbuf from @file_name and returns it.  This pixbuf is scaled
> >  * from the size indicated by the file by a factor of @x_zoom and @y_zoom. If the
> >  * resulting pixbuf would be larger than max_width/max_heigh it is uniformly scaled
> >  * down to fit in that rectangle.\302\240The caller must assume the reference to the
> >  * returned pixbuf. If an error occurred, @error is set and %NULL is returned.
> >  *
> >  * Return value: A newly allocated #GdkPixbuf, or %NULL
> >  **/
> >
> > GdkPixbuf*
> > rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
> >                                         double x_zoom,
> >                                         double y_zoom,
> >                                         gint max_width,
> >                                         gint max_height,
> >                                         GError **error);
> >
> >
> > I tried to pull what I need from the swing components (JSVGCanvas and
> > superclasses) and from the transcoder package, but I can't follow all of
> > what's going on under the hood.  Is there something that I'm missing?
> >
> >    michael
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-users-help@xml.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>


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


Re: SVG --> static BufferedImage

Posted by Vincent Hardy <vi...@sun.com>.
Hello Michael,

There is support for what you are looking for. First, there is a command 
line application to generate rasters from SVG content:

http://xml.apache.org/batik/svgrasterizer.html

and there is a generic transcoding API:

http://xml.apache.org/batik/rasterizerTutorial.html

Vincetn.

heuermh@primushost.com wrote:
> Hello,
> 
> I'd just like to create a static BufferedImage from a SVG document, with
> some ability to specify image size and zoom factor, much like this API
> from librsvg from the GNOME 2.2 platform,
> 
> /**
>  * rsvg_pixbuf_from_file_at_zoom_with_max:
>  * @file_name: A file name
>  * @x_zoom: The horizontal zoom factor
>  * @y_zoom: The vertical zoom factor
>  * @max_width: The requested max width
>  * @max_height: The requested max height
>  * @error: return location for errors
>  *
>  * Loads a new #GdkPixbuf from @file_name and returns it.  This pixbuf is scaled
>  * from the size indicated by the file by a factor of @x_zoom and @y_zoom. If the
>  * resulting pixbuf would be larger than max_width/max_heigh it is uniformly scaled
>  * down to fit in that rectangle.\302\240The caller must assume the reference to the
>  * returned pixbuf. If an error occurred, @error is set and %NULL is returned.
>  *
>  * Return value: A newly allocated #GdkPixbuf, or %NULL
>  **/
> 
> GdkPixbuf*
> rsvg_pixbuf_from_file_at_zoom_with_max (const gchar *file_name,
>                                         double x_zoom,
>                                         double y_zoom,
>                                         gint max_width,
>                                         gint max_height,
>                                         GError **error);
> 
> 
> I tried to pull what I need from the swing components (JSVGCanvas and
> superclasses) and from the transcoder package, but I can't follow all of
> what's going on under the hood.  Is there something that I'm missing?
> 
>    michael
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 



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