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 jdomuser <ha...@live.com> on 2008/10/03 11:56:44 UTC
how to export images from a svg file
Hello, i have downloaded all .jar files related to batik. I need to retrieve
images from a svg file and save them to disk. I convert swf to svg by using
openoffice converter.
How can i retrieve images from the svg representation and save them to disk?
thanks in advance.
--
View this message in context: http://www.nabble.com/how-to-export-images-from-a-svg-file-tp19794886p19794886.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by Cameron McCormack <ca...@mcc.id.au>.
jdomuser:
> Thank you very much, i think it will help; now i should retrieve the base64
> string to feed ParsedURL. To retrive the base64 string, i do the following:
> ......
> if (id != null && id.getNodeValue().contains("Picture")) {
> Node grandchild = child.getLastChild();
> NodeList grandchildren = grandchild.getChildNodes();
> if (grandchildren.getLength() == 1) { // base 64 image
> SVGOMImageElement ie = (SVGOMImageElement)
> grandchildren.item(0).getLastChild();
> ......
> but after that, i cant get the string with the line "String image =
> ie.getHref().getAnimVal();"
What do you get with the above code?
If you don’t have any animations, then you can also use
String image =
ie.getAttributeNS("http://www.w3.org/1999/xlink", "href");
to get the value of the @xlink:href attribute.
Cameron
(in Korea on vacation, so unable to reply quickly)
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by jdomuser <ha...@live.com>.
Thank you very much, i think it will help; now i should retrieve the base64
string to feed ParsedURL. To retrive the base64 string, i do the following:
......
if (id != null && id.getNodeValue().contains("Picture")) {
Node grandchild = child.getLastChild();
NodeList grandchildren = grandchild.getChildNodes();
if (grandchildren.getLength() == 1) { // base 64 image
SVGOMImageElement ie = (SVGOMImageElement)
grandchildren.item(0).getLastChild();
......
but after that, i cant get the string with the line "String image =
ie.getHref().getAnimVal();"
would you give any suggestion?
Best Regards.
Cameron McCormack-4 wrote:
>
>
> OK. You can use the ParsedURL class to get an InputStream from that
> data: URI:
>
>
> http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/util/ParsedURL.html
>
> You can then pass that InputStream to the constructor of
> org.apache.batik.ext.awt.image.codec.png.PNGImageDecoder, then call
> decodeAsRenderedImage(0) on it PNGImageDecoder. That will return you a
> RenderedImage:
>
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/RenderedImage.html
>
> Then you can convert the RenderedImage to a BufferedImage, using code
> like shown here:
>
> http://www.jguru.com/faq/view.jsp?EID=114602
>
> Once you’ve made the changes to your image, use the PNGImageEncoder
> class, which will write the PNG data to an OutputStream. For that
> OutputStream, supply an instance of Base64EncoderStream that is wrapped
> by a StringWriter. Then set the @xlink:href attribute of the <image>
> element to be "data:image/png;base64," + yourStringWriter.
>
> Hope that helps,
>
> Cameron
>
> --
> Cameron McCormack ≝ http://mcc.id.au/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/how-to-export-alter-images%28image-data%29-of-an-svg-file-tp19794886p19840613.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by jdomuser <ha...@live.com>.
thanks for all suggestions, works perfectly.
Cameron McCormack-4 wrote:
>
>
> OK. You can use the ParsedURL class to get an InputStream from that
> data: URI:
>
>
> http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/util/ParsedURL.html
>
> You can then pass that InputStream to the constructor of
> org.apache.batik.ext.awt.image.codec.png.PNGImageDecoder, then call
> decodeAsRenderedImage(0) on it PNGImageDecoder. That will return you a
> RenderedImage:
>
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/RenderedImage.html
>
> Then you can convert the RenderedImage to a BufferedImage, using code
> like shown here:
>
> http://www.jguru.com/faq/view.jsp?EID=114602
>
> Once you’ve made the changes to your image, use the PNGImageEncoder
> class, which will write the PNG data to an OutputStream. For that
> OutputStream, supply an instance of Base64EncoderStream that is wrapped
> by a StringWriter. Then set the @xlink:href attribute of the <image>
> element to be "data:image/png;base64," + yourStringWriter.
>
> Hope that helps,
>
> Cameron
>
> --
> Cameron McCormack ≝ http://mcc.id.au/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/how-to-export-alter-images%28image-data%29-of-an-svg-file-tp19794886p19899814.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by Cameron McCormack <ca...@mcc.id.au>.
Cameron McCormack:
> > Or (another possibility): do you want to extract base64-encoded image
> > data from an SVG document? For example when you have:
> >
> > <image xlink:href='data:image/png,Abshfdsy39…'/>
jdomuser:
> Yes, thats what i wan to do. I will convert it to a BufferedImage(or some
> other image class) and save to disk, modify it with some other code, and
> then embed the modified image to its old position..
OK. You can use the ParsedURL class to get an InputStream from that
data: URI:
http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/util/ParsedURL.html
You can then pass that InputStream to the constructor of
org.apache.batik.ext.awt.image.codec.png.PNGImageDecoder, then call
decodeAsRenderedImage(0) on it PNGImageDecoder. That will return you a
RenderedImage:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/image/RenderedImage.html
Then you can convert the RenderedImage to a BufferedImage, using code
like shown here:
http://www.jguru.com/faq/view.jsp?EID=114602
Once you’ve made the changes to your image, use the PNGImageEncoder
class, which will write the PNG data to an OutputStream. For that
OutputStream, supply an instance of Base64EncoderStream that is wrapped
by a StringWriter. Then set the @xlink:href attribute of the <image>
element to be "data:image/png;base64," + yourStringWriter.
Hope that helps,
Cameron
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by jdomuser <ha...@live.com>.
Yes, thats what i wan to do. I will convert it to a BufferedImage(or some
other image class) and save to disk, modify it with some other code, and
then embed the modified image to its old position..
Cameron McCormack-4 wrote:
>
>
> Or (another possibility): do you want to extract base64-encoded image
> data from an SVG document? For example when you have:
>
> <image xlink:href='data:image/png,Abshfdsy39…'/>
>
> in there?
>
> --
> Cameron McCormack ≝ http://mcc.id.au/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/how-to-export-alter-images%28image-data%29-of-an-svg-file-tp19794886p19827041.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by Cameron McCormack <ca...@mcc.id.au>.
jdomuser:
> thanks but, i want to retrieve the image data that is embedded in the svg
> file, and save them to file, and set them back to the same positions after
> scaling/filtering etc. Is it possible to do that with batik?
Or (another possibility): do you want to extract base64-encoded image
data from an SVG document? For example when you have:
<image xlink:href='data:image/png,Abshfdsy39…'/>
in there?
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by Cameron McCormack <ca...@mcc.id.au>.
jdomuser:
> thanks but, i want to retrieve the image data that is embedded in the svg
> file, and save them to file, and set them back to the same positions after
> scaling/filtering etc. Is it possible to do that with batik?
I’m not sure what you mean, exactly. Do you want to load an SVG
document, modify it a bit (e.g. add a transform or a filter), then save
the XML back out to a file (or rasterize it after modification)?
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by jdomuser <ha...@live.com>.
thanks but, i want to retrieve the image data that is embedded in the svg
file, and save them to file, and set them back to the same positions after
scaling/filtering etc. Is it possible to do that with batik?
Cameron McCormack-4 wrote:
>
>
> If you want to convert SVG files to a raster image format, like PNG or
> JPEG, you can use the command-line rasterizer tool:
>
> http://xmlgraphics.apache.org/batik/tools/rasterizer.html
>
> --
> Cameron McCormack ≝ http://mcc.id.au/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/how-to-export-alter-images%28image-data%29-of-an-svg-file-tp19794886p19823345.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: how to export images from a svg file
Posted by Cameron McCormack <ca...@mcc.id.au>.
jdomuser:
> Hello, i have downloaded all .jar files related to batik. I need to retrieve
> images from a svg file and save them to disk. I convert swf to svg by using
> openoffice converter.
> How can i retrieve images from the svg representation and save them to disk?
> thanks in advance.
If you want to convert SVG files to a raster image format, like PNG or
JPEG, you can use the command-line rasterizer tool:
http://xmlgraphics.apache.org/batik/tools/rasterizer.html
--
Cameron McCormack ≝ http://mcc.id.au/
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org