我正在尝试使用 uil 显示 svg。我使用 androidsvg ( http://code.google.com/p/androidsvg/ ) 编写了自己的图像解码器,如下所示:
public class SVGImageDecoder implements ImageDecoder {
@Override
public Bitmap decode(ImageDecodingInfo imageDecodingInfo) throws IOException {
Bitmap decodedBitmap = null;
InputStream inputStream = getImageStream(imageDecodingInfo);
SVG svg = null;
try {
svg = SVG.getFromInputStream(inputStream);
} catch (SVGParseException e) {
e.printStackTrace();
}
Picture picture = svg.renderToPicture();
PictureDrawable pictureDrawable = new PictureDrawable(picture);
decodedBitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),
pictureDrawable.getIntrinsicHeight(), Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(decodedBitmap);
// Clear background to white
canvas.drawRGB(255, 255, 255);
svg.renderToCanvas(canvas);
return decodedBitmap;
}
protected InputStream getImageStream(ImageDecodingInfo decodingInfo) throws IOException {
return decodingInfo.getDownloader().getStream(decodingInfo.getImageUri(), decodingInfo.getExtraForDownloader());
}
}
显示 SVG,但出现以下问题:
1.) 颜色和图片未渲染和显示 2.) 渲染时间过长,logcat 显示如下内容:
01-06 23:48:15.310 15505-15506/de.phcom.epaper2 D/dalvikvm:GC_CONCURRENT 释放 2048K,10% 空闲 26540K/29187K,暂停 1ms+29ms 01-06 23:48:15.645 15505-15506/de.phcom.epaper2 D/dalvikvm:GC_CONCURRENT 释放 2046K,10% 空闲 26541K/29187K,暂停 2ms+27ms 01-06 23:48:15.970 15505-15506/de.phcom.epaper2 D/dalvikvm﹕GC_CONCURRENT 已释放 2047K,10% 可用 26542K/29187K,暂停 1ms+28ms 01-06 23:48:16.305 15505-15506/de.phcom.epaper2 D/dalvikvm:GC_CONCURRENT 释放 2049K,10% 空闲 26541K/29187K,暂停 2ms+29ms 01-06 23:48:16.650 15505-15506/de.phcom.epaper2 D/dalvikvm﹕GC_CONCURRENT 已释放 2051K,10% 可用 26538K/29187K,暂停 1ms+27ms
那么,如何提高性能并解决问题呢?有没有更好的方法将 svgs 与 uil 集成?