Example usage for android.graphics Canvas getHeight

List of usage examples for android.graphics Canvas getHeight

Introduction

In this page you can find the example usage for android.graphics Canvas getHeight.

Prototype

public int getHeight() 

Source Link

Document

Returns the height of the current drawing layer

Usage

From source file:com.abhinavjhanwar.android.egg.neko.NekoShortcuts.java

private static Bitmap getDarkIcon(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    if (drawable != null) {
        drawable.setColorFilter(0xFF616161, PorterDuff.Mode.MULTIPLY);
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);/* ww  w . j  av  a  2 s  .c  o  m*/
        return bitmap;
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}

From source file:com.jameswolfeoliver.pigeon.Utilities.Utils.java

public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);//from  ww  w. j av  a2  s  .c  om
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:com.nextgis.maplibui.util.NotificationHelper.java

public static Bitmap getLargeIcon(int iconResourceId, Resources resources) {
    Bitmap icon = BitmapFactory.decodeResource(resources, iconResourceId);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return icon;

    int iconSize = ControlHelper.dpToPx(40, resources);
    int innerIconSize = ControlHelper.dpToPx(24, resources);
    icon = Bitmap.createScaledBitmap(icon, iconSize, iconSize, false);
    Bitmap largeIcon = icon.copy(Bitmap.Config.ARGB_8888, true);
    icon = Bitmap.createScaledBitmap(icon, innerIconSize, innerIconSize, false);

    Canvas canvas = new Canvas(largeIcon);
    int center = canvas.getHeight() / 2;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(resources.getColor(R.color.accent));
    canvas.drawCircle(center, center, center, paint);
    paint.setColor(Color.WHITE);//from ww w  .  ja va 2s .c om
    canvas.drawBitmap(icon, center - icon.getWidth() / 2, center - icon.getWidth() / 2, paint);

    return largeIcon;
}

From source file:Main.java

/**
 * Create darkened version of input drawable offset.
 *
 * @param res//  ww  w  . java 2s  .c  o  m
 * @param inImage
 * @param offsetX
 * @param offsetY
 * @param blurRadius   Not currently used.
 * @param shadowColor
 * @return
 */
public static BitmapDrawable shadowImage(Resources res, Drawable inImage, int offsetX, int offsetY,
        float blurRadius, int shadowColor) {

    Bitmap inBitmap;
    if (inImage instanceof BitmapDrawable) {
        inBitmap = ((BitmapDrawable) inImage).getBitmap();
    } else {
        // Bitmap from drawable
        int imgWidth = inImage.getIntrinsicWidth();
        int imgHeight = inImage.getIntrinsicHeight();
        inBitmap = Bitmap.createBitmap(imgWidth, imgHeight, Bitmap.Config.ARGB_8888);
        Canvas bottomCanvas = new Canvas(inBitmap);
        inImage.setBounds(0, 0, bottomCanvas.getWidth(), bottomCanvas.getHeight());
        inImage.draw(bottomCanvas);
    }

    Bitmap blurBitmap = shadowBitmap(inBitmap, offsetX, offsetY, blurRadius, shadowColor);
    return new BitmapDrawable(res, blurBitmap);
}

From source file:com.destin.sehaikun.DrawableUtils.java

public static Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }/*from w ww.  jav  a  2s  .  co m*/

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.y20k.trackbook.helpers.NotificationHelper.java

private static Bitmap getBitmap(int resource) {
    VectorDrawableCompat drawable = VectorDrawableCompat.create(mService.getResources(), resource, null);
    if (drawable != null) {
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);// w ww. jav  a  2  s.  c  om
        return bitmap;
    } else {
        return null;
    }
}

From source file:Main.java

public static void drawFPS(Canvas canvas, String text) {
    if (PAINT_FPS == null) {
        PAINT_FPS = new Paint();
        PAINT_FPS.setColor(Color.RED);
        PAINT_FPS.setTextSize(30);//w w  w .  ja  v a 2 s .co  m
    }
    int top = canvas.getHeight() - 50;

    clearCanvas(canvas, 10, top - 50, (int) (PAINT_FPS.measureText(text) + 20), canvas.getHeight());
    canvas.drawText(text, 10, top, PAINT_FPS);
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getResizedDrawable(@NonNull Context context, @DrawableRes int drawableRes,
        @DimenRes int dimenRes) {
    try {/*from   ww w.  jav  a 2  s  .  c  o  m*/
        Drawable drawable = getDrawable(context, drawableRes);
        if (drawable == null)
            return null;

        int size = context.getResources().getDimensionPixelSize(dimenRes);

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

        return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, size, size, true));
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.d(Log.getStackTraceString(e));
        return null;
    }
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getDefaultImage(@NonNull Context context, @DrawableRes int res) {
    try {/* ww  w.j ava 2s . c o m*/
        int color = ColorHelper.getAttributeColor(context, android.R.attr.textColorSecondary);
        int padding = context.getResources().getDimensionPixelSize(R.dimen.default_image_padding);

        Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res);
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

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

        Bitmap tintedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() + padding,
                Bitmap.Config.ARGB_8888);
        Canvas tintedCanvas = new Canvas(tintedBitmap);
        int background = ColorHelper.getAttributeColor(context, R.attr.card_background);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setAntiAlias(true);
        tintedCanvas.drawColor(background, PorterDuff.Mode.ADD);
        tintedCanvas.drawBitmap(bitmap, (tintedCanvas.getWidth() - bitmap.getWidth()) / 2,
                (tintedCanvas.getHeight() - bitmap.getHeight()) / 2, paint);
        return new BitmapDrawable(context.getResources(), tintedBitmap);
    } catch (Exception | OutOfMemoryError e) {
        return null;
    }
}

From source file:com.zandbee.floatingtitlebar.FloatingTitleBarActivity.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/* ww  w .  j  a v a 2s.co m*/

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

    return bitmap;
}