Drawable getOpacity - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Drawable getOpacity method.

This code example shows how to use the following methods:draw, getBounds, getIntrinsicHeight, getIntrinsicWidth, getOpacity
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
            } 
        } 
        int iconWidth = icon.getIntrinsicWidth();
        int iconHeight = icon.getIntrinsicHeight();
 
        if (width > 0 && height > 0) {
            if (width < iconWidth || height < iconHeight || scale != 1.0f) {
                final float ratio = (float) iconWidth / iconHeight;
 
                if (iconWidth > iconHeight) {
                    height = (int) (width / ratio);
                } else if (iconHeight > iconWidth) {
                    width = (int) (height * ratio);
                } 
 
                final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ?
                            Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds
     * 将Drawable转化为Bitmap 
     * @param drawable 
     * @return 
     */ 
    public static Bitmap drawableToBitmap(Drawable drawable) {
        int width = drawable.getIntrinsicWidth();
        int height = drawable.getIntrinsicHeight();
        Bitmap bitmap = Bitmap.createBitmap(width, height, drawable
                .getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);
        return bitmap;
 
    } 
 
    /** 
     * 获得圆角图片的方法 
     * @param bitmap 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds
	 */ 
	public static Bitmap DrawableToBitmap(Drawable drawable) {  
	    try {   
	        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);  
	        // canvas.setBitmap(bitmap);   
	        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable  
	                .getIntrinsicHeight());  
	        drawable.draw(canvas);  
	   
	        return bitmap;  
	    } catch (OutOfMemoryError e) {  
	        e.printStackTrace();  
	        return null;   
	    }   
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds
	private MessageDigest mDigest;
 
	public static Bitmap drawableToBitmap(Drawable drawable) {
		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;
	} 
 
	public ImageManager(Context context) {
		mContext = context;
		mCache = new HashMap<String, SoftReference<Bitmap>>();
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds
        return bitmap;
    } 
 
    public static Bitmap drawableToBitmap(Drawable drawable) {
 
        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;
    } 
 
    public static Drawable zoomDrawable(Drawable drawable, int w, int h) {
        int width = drawable.getIntrinsicWidth();
        int height = drawable.getIntrinsicHeight();

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getOpacity
        public void setColorFilter(ColorFilter cf) {
            mRealDrawable.setColorFilter(cf);
        } 
        @Override 
        public int getOpacity() { 
            return mRealDrawable.getOpacity();
        } 
    } 
 
    public TargetDrawable(Resources res, int resId) {
        this(res, resId == 0 ? null : res.getDrawable(resId));
    } 
 
    public TargetDrawable(Resources res, Drawable drawable) {
        // Mutate the drawable so we can animate shared drawable properties. 
        mDrawable = drawable != null ? drawable.mutate() : null;
        resizeDrawables(); 
        setState(STATE_INACTIVE);
    } 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getBounds, getIntrinsicHeight, getIntrinsicWidth, getOpacity
             
            if (icon == null) {
                return null; 
            } 
 
            final int iconWidth = icon.getIntrinsicWidth();
            final int iconHeight = icon.getIntrinsicHeight();
 
            if (icon instanceof PaintDrawable) {
                PaintDrawable painter = (PaintDrawable) icon;
                painter.setIntrinsicWidth(width);
                painter.setIntrinsicHeight(height);
            } 
 
            if (width > 0 && height > 0) {
                if (width < iconWidth || height < iconHeight) {
                    final float ratio = (float) iconWidth / iconHeight;
 
                    if (iconWidth > iconHeight) {
                        height = (int) (width / ratio);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, getOpacity, setBounds
	 * @param drawable 
	 * @return 
	 */ 
	public static Bitmap drawableToBitmap(Drawable drawable) {  
		if (drawable != null) {
			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;
		}else { 
			return null; 
		} 
    }   
	 
	/** 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getOpacity
        public void setColorFilter(ColorFilter cf) {
            mRealDrawable.setColorFilter(cf);
        } 
        @Override 
        public int getOpacity() { 
            return mRealDrawable.getOpacity();
        } 
    } 
 
    public TargetDrawable(Resources res, int resId) {
        mResourceId = resId;
        setDrawable(res, resId);
    } 
 
    public void setDrawable(Resources res, int resId) {
        // Note we explicitly don't set mResourceId to resId since we allow the drawable to be 
        // swapped at runtime and want to re-use the existing resource id for identification. 
        Drawable drawable = resId == 0 ? null : res.getDrawable(resId);
        // Mutate the drawable so we can animate shared drawable properties. 
        mDrawable = drawable != null ? drawable.mutate() : null;
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
getOpacity Method Overview
Return the opacity/transparency of this Drawable.
See Code Examples for other Android Drawable Methods: