2011-07-21 9 views
2

SVGグラフィックスを使用して私の最初のアプリケーションを開発していますが、デバイスの画面の幅と高さに合わせてSVG背景イメージの自動スケーリングはどうでしょうか?それは可能ですか、または私は異なるディスプレイの解像度のために複数のファイルを持たなければなりませんJ2MEのSVGグラフィックス自動スケーリング

答えて

1

私は具体的にJ2MEについてはわかりませんが、これは通常、ルートSVG要素のviewBox属性を設定し、 100%。例えばここを参照してください:

<?xml version="1.0" standalone="no"?> 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 
<svg version="1.1" 
     viewBox="0 0 1500 1000" preserveAspectRatio="none" 
     xmlns="http://www.w3.org/2000/svg" 
     width="100%" height="100%"> 
     <desc>Example ViewBox - uses the viewBox 
     attribute to automatically create an initial user coordinate 
     system which causes the graphic to scale to fit into the 
     viewport no matter what size the viewport is.</desc> 
     <!-- This rectangle goes from (0,0) to (1500,1000) in user space. 
     Because of the viewBox attribute above, 
     the rectangle will end up filling the entire area 
     reserved for the SVG content. --> 
     <rect x="0" y="0" width="1500" height="1000" 
     fill="yellow" stroke="blue" stroke-width="12" /> 
     <!-- A large, red triangle --> 
     <path fill="red" d="M 750,100 L 250,900 L 1250,900 z"/> 
     <!-- A text string that spans most of the viewport --> 
     <text x="100" y="600" font-size="200" font-family="Verdana" > 
     Stretch to fit 
     </text> 
</svg> 
ここ

ライブデモ:http://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute

:画像の縦横比を維持する方法については、こちらの仕様を参照してください http://stuff.echo-flow.com/stackoverflow/viewbox.svg

関連する問題