Thanks Cameron,
The code that you gave fixed partially the problem : there was still a black
line on top of the generated GIF. I finally corrected the problem by using
the following code, which use another way to produce a BufferedImage :
(Simplified version - procedural - some objects creation omit, used fake
static objects instead )
// First create an outputStream to hold the hold the SVGDocument
ByteArrayOutputStream ostream = new ByteArrayOutputStream ();
// Write the SVGDocument in the ByteArrayOutputStream using DOMUtilities to
Serializes it.
PrintWriter writer = new PrintWriter(ostream );
DOMUtilities.writeDocument(svgDocument, writer);
writer.flush();
writer.close();
ByteArrayInputStream inputStream = new ByteArrayInputStream(new String
(ostream .toByteArray()).getBytes("utf-8"));
TranscoderInput input = new TranscoderInput(inputStream );
ImageTranscoder.transcode(input, null);
After, the "transcode" code in ImageTranscoder does what you suggested :
> if(hints.containsKey(KEY_BACKGROUND_COLOR))
> {
> Paint bgcolor = (Paint)hints.get(KEY_BACKGROUND_COLOR);
> g2d.setComposite(AlphaComposite.SrcOver);
> g2d.setPaint(bgcolor);
> g2d.fillRect(0, 0, w, h);
> }
The g2d.setComposite(AlphaComposite.SrcOver); line seems to correct the
other problem of the black line...
Thanks!!!!
Cameron McCormack-4 wrote:
>
> Hi Sébastien.
>
> Hamel, Sébastien:
>> The simplified code used to convert from SVG to the BufferedImage is the
>> following
>>
>> public BufferedImage getImage(SVGDocument svgDocument, int width,
>> int height) {
>> // Paint svg into image buffer
>> //BufferedImage bufferedImage = new BufferedImage(width,
>> height,
>> // BufferedImage.TYPE_USHORT_565_RGB);
>> BufferedImage bufferedImage = new BufferedImage(width,
>> height,
>> BufferedImage.TYPE_3BYTE_BGR);
>> Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
>>
>> // For a smooth graphic with no jagged edges or rastorized
>> look.
>>
>>
>> g2d.setBackground(Color.WHITE);
>
> I’m wondering whether it is an issue of what the BufferedImage is filled
> with when you first create it. Since you use TYPE_3BYTE_BGR, there is
> no alpha channel, so the BufferedImage will be filled with some solid
> colour.
>
> How about doing a fillRect() to fill the BufferdImage with white
> explicitly (assuming that’s what you want as your background colour)?
>
> g2d.setColor(Color.WHITE);
> g2d.fillRect(0, 0, width, height);
>
> --
> Cameron McCormack ≝ http://mcc.id.au/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://www.nabble.com/BufferedImage-black-background-problem-tp22955348p23085372.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]