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 Carsten Birn <Ca...@rose.de> on 2004/09/24 14:34:23 UTC
Possible problem with SVGGraphics2D drawImage
Hi
I have discovered a problem when trying to store a GIF image using the SVGGraphics2D context. I am calling the drawImage(BufferedImage, posX, posY, ImageObserver) method.
When i have an Icon with 1 color(ore more) Black + Transparency 15x16 (Created with GIMP) the result is a line
from top till bottom on the right side. (See Example)
I have supplied an example (Ground.gif) of the input and the result (shown below).
When anyone has experienced similar problems or have a clue i would appreciate it a lot.
Regards Carsten
Output
- - - Start
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="'sansserif'" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto">
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs" />
<g>
<g fill="white" stroke="white">
<rect width="35" x="0" height="41" y="0" stroke="none" />
</g>
<g>
<image x="10" y="15" width="15" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAQAQMAAADzmLdHAAAABlBMVEUAAAD///+l
2Z/dAAAAAnRSTlP/AOW3MEoAAAAcSURBVHjaY/jDwMQARQjwHyzyECYlz8D0F8oG
AGT/BA/F2Kp3AAAAAElFTkSuQmCC" height="16" preserveAspectRatio="none" />
<rect width="5" x="15" height="5" y="10" stroke="none" />
</g>
</g>
</svg>
- - - End
Re: Possible problem with SVGGraphics2D drawImage
Posted by Carsten Birn <Ca...@rose.de>.
Hi Thomas
You are right about the drawImage method.
The strange thing is that my icon is drawn correctly when it is painted into a JPanel.
I load my icons using javax.imageio.ImageIO.read and this returns a bufferedImage.
I've found an approach that works and it is:
drawImage(BufferedImage, BufferedImageOP, posX,posY)
BufferedImageOP = AffineTransformOP(AffineTransform, TYPE_BILINEAR);
Thanks for the rapid responses.
Carsten Birn
Am Fr 24.09.2004 14:50, Thomas DeWeese <Th...@Kodak.com> schrieb:
> Hi Carsten,
>
> Carsten Birn wrote:
>
> > I have discovered a problem when trying to store a GIF image using the
> > SVGGraphics2D context. I am calling the drawImage(BufferedImage, posX,
> > posY, ImageObserver) method.
>
> I think you are actually calling:
> drawImage(Image, posX, posY, ImageObserver)
>
> This is an important distinction because an 'Image' loads
> asynchronously so it may not be complete when you draw it. When
> you draw to a AWT Component it will refresh it's self as the image
> updates (like a web browser) - This is what the ImageObserver nonsense
> is about. But when drawing to something like a BufferedImage (or in
> this case the SVGGraphics2D) it's your responsibility to ensure that
> the image is fully loaded - otherwise it renders what it has at the
> moment.
>
> You could look at using the MediaTracker Interface. Or there
> is a little bit simpler interface in:
> batik.ext.awt.image.spi.JDKRegistryEntry.MyImgObs.
>
> I am only 90% certain this is the cause of the problem so I
> would be interested to know if ensuring the image was fully
> loaded does in fact solve the problem.
>
> Perhaps a quicker way to check would be to add a sleep to
> your code for a few sec - which should give it plenty of time
> to load the image. The correct solution is to use some form
> of ImageObserver (like MediaTracker).
>
> > When i have an Icon with 1 color(ore more)
> > Black + Transparency 15x16 (Created with GIMP) the result is a line
> > from top till bottom on the right side. (See Example)
> > I have supplied an example (Ground.gif) of the input and the result
> > (shown below).
> >
> > When anyone has experienced similar problems or have a clue i would
> > appreciate it a lot.
>
>
> ---------------------------------------------------------------------
> 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: Possible problem with SVGGraphics2D drawImage
Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Carsten,
Carsten Birn wrote:
> I have discovered a problem when trying to store a GIF image using the
> SVGGraphics2D context. I am calling the drawImage(BufferedImage, posX,
> posY, ImageObserver) method.
I think you are actually calling:
drawImage(Image, posX, posY, ImageObserver)
This is an important distinction because an 'Image' loads
asynchronously so it may not be complete when you draw it. When
you draw to a AWT Component it will refresh it's self as the image
updates (like a web browser) - This is what the ImageObserver nonsense
is about. But when drawing to something like a BufferedImage (or in
this case the SVGGraphics2D) it's your responsibility to ensure that
the image is fully loaded - otherwise it renders what it has at the
moment.
You could look at using the MediaTracker Interface. Or there
is a little bit simpler interface in:
batik.ext.awt.image.spi.JDKRegistryEntry.MyImgObs.
I am only 90% certain this is the cause of the problem so I
would be interested to know if ensuring the image was fully
loaded does in fact solve the problem.
Perhaps a quicker way to check would be to add a sleep to
your code for a few sec - which should give it plenty of time
to load the image. The correct solution is to use some form
of ImageObserver (like MediaTracker).
> When i have an Icon with 1 color(ore more)
> Black + Transparency 15x16 (Created with GIMP) the result is a line
> from top till bottom on the right side. (See Example)
> I have supplied an example (Ground.gif) of the input and the result
> (shown below).
>
> When anyone has experienced similar problems or have a clue i would
> appreciate it a lot.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: Possible problem with SVGGraphics2D drawImage
Posted by Robert Marcano <ro...@marcanoonline.com>.
On Fri, 2004-09-24 at 08:34, Carsten Birn wrote:
> Hi
>
> I have discovered a problem when trying to store a GIF image using the SVGGraphics2D context. I am calling the drawImage(BufferedImage, posX, posY, ImageObserver) method.
> When i have an Icon with 1 color(ore more) Black + Transparency 15x16 (Created with GIMP) the result is a line
> from top till bottom on the right side. (See Example)
> I have supplied an example (Ground.gif) of the input and the result (shown below).
Which program are you using to see the file? I do not see any vertical
line, except for the line that is part of the ground icon. I looked the
image using my email client (Evolution), Gimp and Mozilla, and there is
no problem with it
>
> When anyone has experienced similar problems or have a clue i would appreciate it a lot.
>
> Regards Carsten
>
> Output
> - - - Start
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
> <svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="'sansserif'" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto">
> <!--Generated by the Batik Graphics2D SVG Generator-->
> <defs id="genericDefs" />
> <g>
> <g fill="white" stroke="white">
> <rect width="35" x="0" height="41" y="0" stroke="none" />
> </g>
> <g>
> <image x="10" y="15" width="15" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAQAQMAAADzmLdHAAAABlBMVEUAAAD///+l
> 2Z/dAAAAAnRSTlP/AOW3MEoAAAAcSURBVHjaY/jDwMQARQjwHyzyECYlz8D0F8oG
> AGT/BA/F2Kp3AAAAAElFTkSuQmCC" height="16" preserveAspectRatio="none" />
> <rect width="5" x="15" height="5" y="10" stroke="none" />
> </g>
> </g>
> </svg>
> - - - End
________________________________________
Robert Marcano
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org