List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
@Deprecated
public BitmapDrawable(java.io.InputStream is)
From source file:Main.java
public static Drawable GetUrlDrawable(String url) { try {//w w w . jav a2 s. co m URL aryURI = new URL(url); URLConnection conn = aryURI.openConnection(); InputStream is = conn.getInputStream(); Bitmap bmp = BitmapFactory.decodeStream(is); return new BitmapDrawable(bmp); } catch (Exception e) { Log.e("ERROR", "urlImage2Drawable failed with image url at " + url, e); return null; } }
From source file:Main.java
/** * convert Bitmap to Drawable//from www.j a v a 2 s .c o m * * @param b * @return */ public static Drawable bitmapToDrawable(Bitmap b) { return b == null ? null : new BitmapDrawable(b); }
From source file:Main.java
/** * Rotate the image./*from w ww. ja v a 2 s . com*/ * * @param drawable */ public static BitmapDrawable rotateImage(BitmapDrawable drawable, int degree) { Bitmap bitmap = drawable.getBitmap(); Matrix matrix = new Matrix(); matrix.postRotate(degree); Bitmap rotatedBMP = Bitmap.createBitmap(drawable.getBitmap(), 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return new BitmapDrawable(rotatedBMP); }
From source file:Main.java
@SuppressWarnings("deprecation") public static void setImageBackground(View view, int width, int height, int ResId, Activity context) { Options opts = new Options(); opts.outHeight = height;/*ww w . j av a2 s .co m*/ opts.outWidth = width; opts.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResId, opts); view.setBackgroundDrawable(new BitmapDrawable(bitmap)); }
From source file:Main.java
public static Drawable changeLocalAvatar(Context context, Uri uri) { ContentResolver cr = context.getContentResolver(); Bitmap bitmap = null;/* w w w .j a v a 2 s.c o m*/ try { bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); } return new BitmapDrawable(bitmap); }
From source file:Main.java
public static Drawable scaleImage(Drawable paramDrawable, float paramFloat1, float paramFloat2) { BitmapDrawable localBitmapDrawable = null; if (paramDrawable != null) { Bitmap localBitmap = ((BitmapDrawable) paramDrawable).getBitmap(); int i = localBitmap.getWidth(); int j = localBitmap.getHeight(); Matrix localMatrix = new Matrix(); localMatrix.postScale(paramFloat1, paramFloat2); localBitmapDrawable = new BitmapDrawable( Bitmap.createBitmap(localBitmap, 0, 0, i, j, localMatrix, true)); }//from www . j a v a2 s .co m return localBitmapDrawable; }
From source file:Main.java
public static Drawable scaleImage(Drawable drawable, float scaleWidth, float scaleHeight) { Drawable resizedDrawable = null;/* w w w . jav a 2 s .com*/ if (drawable != null) { Bitmap bitmapOrg = ((BitmapDrawable) drawable).getBitmap(); int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); resizedDrawable = new BitmapDrawable(resizedBitmap); } return resizedDrawable; }
From source file:Main.java
public static Drawable zoomDrawable(Drawable drawable, int w, int h) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap oldbmp = drawableToBitmap(drawable); Matrix matrix = new Matrix(); float sx = ((float) w / width); float sy = ((float) h / height); matrix.postScale(sx, sy);/*from w w w.j a v a 2s . c o m*/ Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); return new BitmapDrawable(newbmp); }
From source file:Main.java
/** * @deprecated Use {@link #getDrawable(Bitmap, Resources)} to ensure * that the drawable has correctly set its target density. */// www .j av a 2 s . c om public static Drawable getDrawable(Bitmap bitmap) { return bitmap == null ? null : new BitmapDrawable(bitmap); }
From source file:Main.java
public static Drawable bitmapToDrawable(Bitmap bitmap) { BitmapDrawable mBitmapDrawable = null; try {/*from w w w . j a va 2 s .c o m*/ if (bitmap == null) { return null; } mBitmapDrawable = new BitmapDrawable(bitmap); } catch (Exception e) { e.printStackTrace(); } return mBitmapDrawable; }