List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
private BitmapDrawable(BitmapState state, Resources res)
From source file:Main.java
public static BitmapDrawable getCachedIcon(Resources res, String packageName, int resId, Options opts) { int displayDpi = res.getDisplayMetrics().densityDpi; Bitmap bitmap = BitmapFactory.decodeFile(getCacheFilePath(packageName, resId), opts); if (bitmap == null) { return null; }/* w w w . j a va2 s. c o m*/ bitmap.setDensity(displayDpi); return new BitmapDrawable(res, bitmap); }
From source file:Main.java
public static Drawable createBitmapDrawable(Context context, Bitmap bitmap) { BitmapDrawable d = new BitmapDrawable(context.getResources(), bitmap); return d.getConstantState().newDrawable(context.getResources()).mutate(); }
From source file:Main.java
/** * Get a mask of color {@code color} using the alpha channel of {@code source}. * @param ctx Context.//from www . j ava 2 s . c o m * @param source Source {@link Drawable} containing the shape alpha channel. * @param color Color of the shape. * @return A {@link Bitmap} containing the shape of the given color. */ public static Drawable getMask(Context ctx, Drawable source, int color) { return new BitmapDrawable(ctx.getResources(), getMask(drawableToBitmap(source), color)); }
From source file:Main.java
public static BitmapDrawable getBitmapDrawableFromUrl(Resources res, URL trueUrl, BitmapFactory.Options mOptions) throws Exception { Bitmap bitmap = null;/*from w w w . j av a 2s. c o m*/ FileInputStream mFS = null; try { mFS = new FileInputStream(trueUrl.getPath()); bitmap = BitmapFactory.decodeFileDescriptor(mFS.getFD(), null, mOptions); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (mFS != null) { mFS.close(); } } return new BitmapDrawable(res, bitmap); }
From source file:Main.java
public static Drawable tintDrawable(Resources res, Drawable src, int color) { return new BitmapDrawable(res, tintBitmap(convertToBitmap(src), color)); }
From source file:Main.java
static private BitmapDrawable bitmapDrawableFromURL(Resources resources, String str_url, boolean scale, int w, int h) {/* w ww . ja v a 2s .co m*/ if (str_url == null || str_url.length() <= 0) return null; BitmapDrawable thumb = null; try { URL url = new URL(str_url); URLConnection connection = url.openConnection(); connection.connect(); InputStream stream = connection.getInputStream(); BufferedInputStream data = new BufferedInputStream(stream); Bitmap bitmap = BitmapFactory.decodeStream(data); if (bitmap != null) { if (scale) thumb = new BitmapDrawable(resources, Bitmap.createScaledBitmap(bitmap, w, h, true)); else thumb = new BitmapDrawable(resources, bitmap); } } catch (MalformedURLException e) { //e.printStackTrace(); } catch (IOException e) { //e.printStackTrace(); } return thumb; }
From source file:Main.java
public static Drawable getDrawable(Bitmap bitmap, Resources resources) { return bitmap == null ? null : new BitmapDrawable(resources, bitmap); }
From source file:Main.java
/** * Retrieves a copy of the specified drawable resource, rotated by a specified angle. * * @param resources The current resources. * @param resourceId The resource ID of the drawable to rotate. * @param angle The angle of rotation./*from w ww .j av a2s. co m*/ * @return Rotated drawable. */ public static Drawable getRotatedDrawable(android.content.res.Resources resources, int resourceId, float angle) { // Get the original drawable and make a copy which will be rotated. Bitmap original = BitmapFactory.decodeResource(resources, resourceId); Bitmap rotated = Bitmap.createBitmap(original.getWidth(), original.getHeight(), Bitmap.Config.ARGB_8888); // Perform the rotation. Canvas tempCanvas = new Canvas(rotated); tempCanvas.rotate(angle, original.getWidth() / 2, original.getHeight() / 2); tempCanvas.drawBitmap(original, 0, 0, null); return new BitmapDrawable(resources, rotated); }
From source file:Main.java
public static void blur(Context context, Bitmap bkg, View view, int width, int height) { float radius = 20; Log.i("hulixia", bkg.getWidth() + "w,h" + bkg.getDensity()); Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft(), -view.getTop()); canvas.drawBitmap(bkg, 0, 0, null);/*from ww w. j a v a 2 s .c o m*/ RenderScript rs = RenderScript.create(context); Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement()); blur.setInput(overlayAlloc); blur.setRadius(radius); blur.forEach(overlayAlloc); overlayAlloc.copyTo(overlay); view.setBackground(new BitmapDrawable(context.getResources(), overlay)); rs.destroy(); }
From source file:Main.java
public static BitmapDrawable loadAppIcon(String iconPath, Context context) { try {/*w w w. ja va 2 s . c o m*/ Bitmap bitmap = null; Bitmap newBitmap = null; if (iconPath != null && !"".equals(iconPath)) { bitmap = BitmapFactory.decodeFile(iconPath); } if (bitmap == null || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) { Log.e("RecommAppsUtils", iconPath + " is not exist"); return null; } int densityDpi = context.getResources().getDisplayMetrics().densityDpi; float scale = densityDpi / STANDARD_DENSITYDPI; newBitmap = zoomBitmap(bitmap, (int) (APP_ICON_WIDTH * scale), (int) (APP_ICON_HEIGHT * scale)); // Log.d("RecommAppsUtils", "densityDpi value : " + densityDpi); return new BitmapDrawable(context.getResources(), newBitmap); } catch (OutOfMemoryError error) { error.printStackTrace(); } return null; }