@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd = new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
private void setCompoundDrawable(Drawable drawable) { DisplayMetrics metrics = new DisplayMetrics(); metrics = view.getContext().getResources().getDisplayMetrics(); if (drawable instanceof BitmapDrawable) { // For some reason this must be set explicitly or otherwise the target density will be // wrong. ((BitmapDrawable) drawable).setTargetDensity(metrics.densityDpi); } Drawable leftDrawable = left ? drawable : null; Drawable topDrawable = top ? drawable : null; Drawable rightDrawable = right ? drawable : null; Drawable bottomDrawable = bottom ? drawable : null; ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable); } }
BitmapDrawable bd = (BitmapDrawable) d; bd.getBitmap().setDensity(DisplayMetrics.DENSITY_DEFAULT); bd.setTargetDensity(DisplayMetrics.DENSITY_DEFAULT);
metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); tempAvatarBitmap = BitmapFactory.decodeStream(fis, null, opt); tempAvatarBitmap = Bitmap.createScaledBitmap( StbApp.getPlayer().get(requestCode-1).getAvatar(), Player.avatarSize, Player.avatarSize, true ); BitmapDrawable drawable = new BitmapDrawable(tempAvatarBitmap); drawable.setTargetDensity(metrics.densityDpi);
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd=new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd = new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd=new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd=new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd = new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") public static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd = new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd=new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd=new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
@SuppressWarnings("deprecation") private static Drawable bitmap2Drawable(Bitmap bm) { if (bm == null) { return null; } BitmapDrawable bd = new BitmapDrawable(bm); bd.setTargetDensity(bm.getDensity()); return new BitmapDrawable(bm); } }
public static Bitmap drawableToBitmap (Drawable drawable) { Bitmap bitmap = null; if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmapDrawable.setAntiAlias(true); bitmapDrawable.setDither(true); bitmapDrawable.setTargetDensity(Integer.MAX_VALUE); if(bitmapDrawable.getBitmap() != null) { return bitmapDrawable.getBitmap(); } } if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel } 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; }
private void addBitmapDrawable(LinearLayout layout, int resource, boolean scale) { Bitmap bitmap; bitmap = loadAndPrintDpi(resource, scale); View view = new View(this); final BitmapDrawable d = new BitmapDrawable(getResources(), bitmap); if (!scale) d.setTargetDensity(getResources().getDisplayMetrics()); view.setBackgroundDrawable(d); view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(), d.getIntrinsicHeight())); layout.addView(view); }
private void addBitmapDrawable(LinearLayout layout, int resource, boolean scale) { Bitmap bitmap; bitmap = loadAndPrintDpi(resource, scale); View view = new View(this); final BitmapDrawable d = new BitmapDrawable(getResources(), bitmap); if (!scale) d.setTargetDensity(getResources().getDisplayMetrics()); view.setBackgroundDrawable(d); view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(), d.getIntrinsicHeight())); layout.addView(view); }
Drawable[] layers = new Drawable[this.itemCount]; Resources resources = getResources(); ImageButton imgButton = (ImageButton) findViewById(R.id.btnItems); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); for (int i = 0; i < this.itemCount; i++) { Bitmap bm = BitmapFactory.decodeResource(resources, R.drawable.icon); BitmapDrawable bmd = new BitmapDrawable(bm); bmd.setGravity(Gravity.TOP); bmd.setTargetDensity(metrics); layers[i] = bmd; } LayerDrawable layerDrawable = new LayerDrawable(layers); int layerTop = 0; for (int i = 0; i < this.itemCount; i++) { int layerLeft = i % 2 == 1 ? 5 : 0; layerDrawable.setLayerInset(i, layerLeft, layerTop, -layerLeft, -layerTop); layerTop += i % 2 == 1 ? 10 : 0; } imgButton.setImageDrawable(layerDrawable);
Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());