xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hans Stoessel" <hstoessel.l...@pm-medici.ch>
Subject Re: JPEGTranscoder: Bad quality - JPEG is displaced
Date Thu, 03 Apr 2008 13:09:11 GMT
Hi Thomas

The code to transcode from SVg to JPEG:

--- START snippet ---
try {
  // create a JPEG transcoder
  JPEGTranscoder t = new JPEGTranscoder();
  // set the transcoding hints
  t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(fQuality));
  t.addTranscodingHint(JPEGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER,  new 
Float(25.4 / fDPI));
  if (m_fJPGWidth > 0.0 && m_fJPGHeight > 0.0) {
    m_fJPGWidth *= (fDPI / 144.0);
    m_fJPGHeight *= (fDPI / 144.0);
    t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new 
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(m_fJPGWidth));
  // create the transcoder input
  String svgURI = new File(sSourceFileName).toURI().toString();
  TranscoderInput input = new TranscoderInput(svgURI);
  // create the transcoder output
  ostream = new FileOutputStream(sTargetFileName);
  TranscoderOutput output = new TranscoderOutput(ostream);
  // save the image
  t.transcode(input, output);
  t = null;
--- END snippet ---

fDPI is 300, and fQuality is 1.0.

Bye the way: The resulting JPEG has a resolution dpi of 96 in IrfanView!


<thomas.deweese@kodak.com> schrieb im Newsbeitrag 
Hi Hans,

news <news@ger.gmane.org> wrote on 03/28/2008 08:48:47 AM:

> I transcode a SVG into a JPEG using the JPEGTranscoder. I set the quality 
> to
> 1.0 (maximum) and the resolution to 300 dpi.

   How are you setting the JPEG quality?

> Quality
> -------
> The qualitiy of the JPEG is bad, especially the texts (fonts). What can I
> do?

   So if you are really setting the JPEG quality it may be something
you just have to live with.  Even with quality set to 1.0 JPEG is
lossy.  For vector graphics PNG is really a much better choice as it
doesn't have ringing problems around high frequency edges.

> JGEP is truncated
> ------------------
> In my SVG I have a black frame around the SVG. When I transcode it to a
> JPEG, the frame, and the whole SVG, is displaced. I mean the content from
> the SVG is moved to the top and to the left. I can see a white space on
> bottom and right where the frame should be.
> What could be wrong?
> Is there a workaround?

    This sort of truncation is almost always caused by incorrectly
set viewBox and width/height attributes (mostly commonly the viewBox).

> By the way: I have the same problem when I trabscode the SVG with the
> PDFTranscoder from FOP. Is something in my SVG wrong?

    Most likely your viewBox on the root SVG element. 

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

View raw message