Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Picture into RemoteViews
    primarykey
    data
    text
    <p>I have some SVGs in my assets folder and I need to dynamically set them in my widget (on an ImageView).</p> <p>I am using this library: <a href="http://code.google.com/p/svg-android/" rel="nofollow">http://code.google.com/p/svg-android/</a></p> <p>This library returns a Picture or a PictureDrawable.</p> <p>The only methods I can see to use on RemoteViews are setImageViewBitmap which obviously takes a bitmap. </p> <p>I tried looking for code to convert a Drawable to a Bitmap like this:</p> <pre><code>PictureDrawable pictureDrawable = svg.createPictureDrawable(); Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); currentBitmap = bitmap; </code></pre> <p>But the bitmap is too small. When I create the bitmap in Illustrator I set the artboard size to 65 which is what comes through on the intrinsic width/height.</p> <p>My widgets can be resized so the ImageView sizes are variable. Even if I set the width and height statically to some large number like this...</p> <pre><code> Bitmap bitmap = Bitmap.createBitmap(300, 300, Config.ARGB_8888); </code></pre> <p>then the resulting bitmap just has a bunch of whitespace below and to the right of a tiny image.</p> <p>I guess I need to somehow draw the picture at a scaled up value as well as creating the Bitmap at size 300. Ideally I could figure out the size of the ImageView at runtime and set the proper sized Bitmap if I knew that. Is this the best approach and how would I do this? Perhaps there is a better approach I don't even know about?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload