Java Code Examples for android.graphics.drawable.BitmapDrawable#getIntrinsicHeight()

The following examples show how to use android.graphics.drawable.BitmapDrawable#getIntrinsicHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PointerIcon.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 *  Get the Bitmap from the Drawable.
 *
 *  If the Bitmap needed to be scaled up to account for density, BitmapDrawable
 *  handles this at draw time. But this class doesn't actually draw the Bitmap;
 *  it is just a holder for native code to access its SkBitmap. So this needs to
 *  get a version that is scaled to account for density.
 */
private Bitmap getBitmapFromDrawable(BitmapDrawable bitmapDrawable) {
    Bitmap bitmap = bitmapDrawable.getBitmap();
    final int scaledWidth  = bitmapDrawable.getIntrinsicWidth();
    final int scaledHeight = bitmapDrawable.getIntrinsicHeight();
    if (scaledWidth == bitmap.getWidth() && scaledHeight == bitmap.getHeight()) {
        return bitmap;
    }

    Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF dst = new RectF(0, 0, scaledWidth, scaledHeight);

    Bitmap scaled = Bitmap.createBitmap(scaledWidth, scaledHeight, bitmap.getConfig());
    Canvas canvas = new Canvas(scaled);
    Paint paint = new Paint();
    paint.setFilterBitmap(true);
    canvas.drawBitmap(bitmap, src, dst, paint);
    return scaled;
}
 
Example 2
Source File: InputOverlayDrawableDpad.java    From citra_android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param res                             {@link Resources} instance.
 * @param defaultStateBitmap              {@link Bitmap} of the default state.
 * @param pressedOneDirectionStateBitmap  {@link Bitmap} of the pressed state in one direction.
 * @param pressedTwoDirectionsStateBitmap {@link Bitmap} of the pressed state in two direction.
 * @param buttonUp                        Identifier for the up button.
 * @param buttonDown                      Identifier for the down button.
 * @param buttonLeft                      Identifier for the left button.
 * @param buttonRight                     Identifier for the right button.
 */
public InputOverlayDrawableDpad(Resources res,
        Bitmap defaultStateBitmap,
        Bitmap pressedOneDirectionStateBitmap,
        Bitmap pressedTwoDirectionsStateBitmap,
        int buttonUp, int buttonDown,
        int buttonLeft, int buttonRight)
{
  mDefaultStateBitmap = new BitmapDrawable(res, defaultStateBitmap);
  mPressedOneDirectionStateBitmap = new BitmapDrawable(res, pressedOneDirectionStateBitmap);
  mPressedTwoDirectionsStateBitmap = new BitmapDrawable(res, pressedTwoDirectionsStateBitmap);

  mWidth = mDefaultStateBitmap.getIntrinsicWidth();
  mHeight = mDefaultStateBitmap.getIntrinsicHeight();

  mButtonType[0] = buttonUp;
  mButtonType[1] = buttonDown;
  mButtonType[2] = buttonLeft;
  mButtonType[3] = buttonRight;
}
 
Example 3
Source File: Utils.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
/**
 *  make a drawable to a bitmap
 * @param drawable drawable you want convert
 * @return converted bitmap
 */
public static Bitmap drawableToBitmap(int size, Drawable drawable) {
    Bitmap bitmap = null;
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        bitmap = bitmapDrawable.getBitmap();
        if (bitmap != null && bitmap.getHeight() > 0) {
            Matrix matrix = new Matrix();
            float scaleHeight = size * 1.0f / bitmapDrawable.getIntrinsicHeight();
            matrix.postScale(scaleHeight, scaleHeight);
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            return bitmap;
        }
    }
    bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
Example 4
Source File: InputOverlayDrawableButton.java    From citra_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param res                {@link Resources} instance.
 * @param defaultStateBitmap {@link Bitmap} to use with the default state Drawable.
 * @param pressedStateBitmap {@link Bitmap} to use with the pressed state Drawable.
 * @param buttonType         Identifier for this type of button.
 */
public InputOverlayDrawableButton(Resources res, Bitmap defaultStateBitmap,
        Bitmap pressedStateBitmap, int buttonType)
{
  mDefaultStateBitmap = new BitmapDrawable(res, defaultStateBitmap);
  mPressedStateBitmap = new BitmapDrawable(res, pressedStateBitmap);
  mButtonType = buttonType;

  mWidth = mDefaultStateBitmap.getIntrinsicWidth();
  mHeight = mDefaultStateBitmap.getIntrinsicHeight();
}
 
Example 5
Source File: MaxScaleImageView.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private void updateScale() {
    Drawable d = getDrawable();
    if(d instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) d;

        // Don't upscale if more than 2x larger
        if (getWidth() > mMaxScale * bd.getIntrinsicWidth()
                && getHeight() > mMaxScale * bd.getIntrinsicHeight()) {
            setScaleType(ScaleType.MATRIX);
            Matrix trans = new Matrix();
            Matrix scale = new Matrix();
            trans.setTranslate((getWidth() - mMaxScale * bd.getIntrinsicWidth())/2, (getHeight() - mMaxScale * bd.getIntrinsicHeight())/2);
            scale.setScale(mMaxScale, mMaxScale);
            Matrix m = new Matrix();
            
            if(isInEditMode()) {
                // WTF? Edit mode consider inversed matrix??
                m.setConcat(scale, trans);
            }else {
                m.setConcat(trans, scale);
            }
            setImageMatrix(m);
        }else {
            setScaleType(ScaleType.CENTER_CROP);
        }
    }
}
 
Example 6
Source File: MapObjectTest.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception
    {
        super.setUp();
        
//        map = new MapWidget(getContext(), "map", 11);
        drawable1 = new BitmapDrawable(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.presence_online));
        drawable2 = new BitmapDrawable(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.presence_online));

        originalDrawableSize = new Size(drawable1.getIntrinsicWidth(), drawable1.getIntrinsicHeight());
//        layer = map.createLayer(1);   
        
        scalableObject = new FakeMapObject("1", drawable1, 10, 10, 0, 0, true, true);
        nonScalableObject = new FakeMapObject("2", drawable2, 100, 100, 0, 0, true, false);
    }