/**
* Renders this SVG document to a Picture object using the specified view defined in the document.
* <p>
* A View is an special element in a SVG document that describes a rectangular area in the document.
* Calling this method with a {@code viewId} will result in the specified view being positioned and scaled
* to the viewport. In other words, use {@link #renderToPicture()} to render the whole document, or use this
* method instead to render just a part of it.
*
* @param viewId the id of a view element in the document that defines which section of the document is to be visible.
* @param widthInPixels the width of the initial viewport
* @param heightInPixels the height of the initial viewport
* @return a Picture object suitable for later rendering using {@code Canvas.drawPicture()}, or null if the viewId was not found.
*/
public Picture renderViewToPicture(String viewId, int widthInPixels, int heightInPixels) {
SvgObject obj = this.getElementById(viewId);
if (obj == null)
return null;
if (!(obj instanceof SVG.View))
return null;
SVG.View view = (SVG.View) obj;
if (view.viewBox == null) {
Log.w(TAG, "View element is missing a viewBox attribute.");
return null;
}
Picture picture = new Picture();
Canvas canvas = picture.beginRecording(widthInPixels, heightInPixels);
Box viewPort = new Box(0f, 0f, (float) widthInPixels, (float) heightInPixels);
SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas, viewPort, this.renderDPI);
renderer.renderDocument(this, view.viewBox, view.preserveAspectRatio, false);
picture.endRecording();
return picture;
}
SVG.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:stepik-android
作者:
评论列表
文章目录