Drawable to Bitmap, Drawable unknown size / size

I have an object object that is a vector. Since you cannot crop (or a clip due to ICS hardware acceleration), it can make sprite animations useless.

I am trying to convert a drawable to a bitmap with a specific size (as a percentage of the lowest screen size for best results).

Of course, the version should be super-memory.

I need help creating a bitmap with a specific size, this is what I got so far:

public Bitmap svgTObitmap(String name, int percentage, int screen_width, int screen_height)
{
    _resID = _context.getResources().getIdentifier( name , "raw" , _context.getPackageName());
    SVG svg = SVGParser.getSVGFromResource(_context.getResources(), _resID);

    Drawable drawable = svg.createPictureDrawable();

    Bitmap bmp = ((BitmapDrawable)drawable).getBitmap();

    return bmp;
}
+3
source share
1 answer

, , Drawable BitmapDrawable. Drawable Bitmap. . :

Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bmp); 
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);

, , , , / .

+7

All Articles