List of usage examples for android.graphics.drawable Drawable setBounds
public void setBounds(int left, int top, int right, int bottom)
From source file:Main.java
public static void drawLeft(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int top = child.getTop() - params.topMargin - drawable.getIntrinsicHeight(); final int bottom = child.getBottom() + params.bottomMargin + drawable.getIntrinsicHeight(); final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth(); final int right = left + drawable.getIntrinsicWidth(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas);//w ww . j a v a2 s .c o m }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (null == drawable) return null; int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;/*from w w w .ja va 2 s.c o m*/ Bitmap bitmap = Bitmap.createBitmap(w, h, config); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); return bitmap; }
From source file:Main.java
public static Bitmap getBitmap(Drawable drawable, boolean scaleBitmap, int width, int height) { Bitmap bitmap;// w w w .j a v a 2 s. com if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } 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); } if (scaleBitmap) { bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true); } return bitmap; }
From source file:com.danimahardhika.android.helpers.core.DrawableHelper.java
@Nullable public static Drawable getResizedDrawable(@NonNull Context context, @NonNull Drawable drawable, float sizeInDp) { try {/*from w w w . j a v a 2s. c o m*/ int size = Math.round(UnitHelper.toPixel(context, sizeInDp)); 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 (OutOfMemoryError e) { return null; } }
From source file:com.acious.android.paginationseekbar.internal.compat.SeekBarCompat.java
public static void setHotspotBounds(Drawable drawable, int left, int top, int right, int bottom) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //We don't want the full size rect, Lollipop ripple would be too big int size = (right - left) / 8; DrawableCompat.setHotspotBounds(drawable, left + size, top + size, right - size, bottom - size); } else {//ww w . ja v a 2s. co m drawable.setBounds(left, top, right, bottom); } }
From source file:net.qiujuer.genius.ui.compat.UiCompat.java
/** * As our DiscreteSeekBar implementation uses a circular drawable on API < 21 * we want to use the same method to set its bounds as the Ripple's hotspot bounds. * * @param drawable Drawable/*from ww w. jav a 2 s .c om*/ * @param left Left * @param top Top * @param right Right * @param bottom Bottom */ public static void setHotspotBounds(Drawable drawable, int left, int top, int right, int bottom) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //We don't want the full size rect, Lollipop ripple would be too big int size = (right - left) / 8; drawable.setHotspotBounds(left + size, top + size, right - size, bottom - size); } else { drawable.setBounds(left, top, right, bottom); } }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable == null || drawable.getIntrinsicWidth() < 0 || drawable.getIntrinsicHeight() < 0) return null; try {/*from w w w. j a va 2 s . c o m*/ Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; } catch (OutOfMemoryError e) { return null; } }
From source file:Main.java
public static int PutImageTargetHeight(Canvas canvas, Drawable image, int x, int y, int height) { // float scale = (float)height / (float)image.getBounds().height(); // int width = (int)Math.round(image.getBounds().width() * scale); float scale = (float) height / (float) image.getIntrinsicHeight(); int width = (int) Math.round((float) image.getIntrinsicWidth() * scale); Rect oldBounds = image.getBounds();//from w w w . j a v a2s . c om image.setBounds(x, y, x + width, y + height); image.draw(canvas); image.setBounds(oldBounds); return width; }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable == null) { return null; }/*from w ww. j a v a2 s . c o m*/ int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; Bitmap bitmap = Bitmap.createBitmap(w, h, config); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); return bitmap; }
From source file:Main.java
public static Bitmap drawableToBitmap(Drawable drawable, float ratio) { int width = (int) Math.ceil(drawable.getIntrinsicWidth() * ratio); int height = (int) Math.ceil(drawable.getIntrinsicHeight() * ratio); Bitmap bitmap = Bitmap.createBitmap(width, height, drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); canvas.scale(ratio, ratio);//from w ww. j a va 2 s . co m drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return bitmap; }