簡體   English   中英

將圖片設置為Android的ImageView

[英]Set Picture to ImageView Android

我在我的代碼中生成圖片,如下所示:

try {
    SVG svg = SVG.getFromResource(this, R.raw.splatter);

    SVGImageView svgImageView = new SVGImageView(this);
    svgImageView.setSVG(svg);
    svgImageView.setLayoutParams(
            new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

    RelativeLayout layout =
            (RelativeLayout) findViewById(R.id.main_layout);

    layout.addView(svgImageView);

    //svg.renderViewToPicture(Integer.toString(R.id.map), layout.getWidth(), layout.getHeight());
    svg.renderToPicture();
} catch (SVGParseException e) {
    e.printStackTrace();
}

現在,我需要將此圖片設置為我的ImageView。 我怎樣才能做到這一點?

您真的需要將svg放入res / raw中嗎? 您可以像正常圖像一樣直接從res / drawable中引用它(即imageView.setImageResource(R.drawable.splatter) )。 這個站點有一個相當不錯的SVG到Android可讀的SVG工具。

Bitmap PicturetoDrawable(Picture picture) {
    return Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM