當前位置: 首頁>>代碼示例>>Java>>正文


Java Drawable.getIntrinsicWidth方法代碼示例

本文整理匯總了Java中android.graphics.drawable.Drawable.getIntrinsicWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.getIntrinsicWidth方法的具體用法?Java Drawable.getIntrinsicWidth怎麽用?Java Drawable.getIntrinsicWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.drawable.Drawable的用法示例。


在下文中一共展示了Drawable.getIntrinsicWidth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } 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;
}
 
開發者ID:robertlevonyan,項目名稱:materialExpansionPanel,代碼行數:22,代碼來源:ExpandableUtils.java

示例2: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap;

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        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;
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:22,代碼來源:ArtworkUtils.java

示例3: onDraw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    Drawable[] drawables = getCompoundDrawables();
    if (drawables != null) {
        Drawable drawableLeft = drawables[0];
        if (drawableLeft != null) {
            float textWidth = getPaint().measureText(getText().toString());
            int drawablePadding = getCompoundDrawablePadding();
            int drawableWidth = 0;
            drawableWidth = drawableLeft.getIntrinsicWidth();
            float bodyWidth = textWidth + drawableWidth + drawablePadding;
            canvas.translate((getWidth() - bodyWidth) / 2 -20, 0);
        }
    }
    super.onDraw(canvas);
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:17,代碼來源:DrawableCenterEditText.java

示例4: setIcon

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public void setIcon(Drawable icon) {
    this.mIcon = icon;
    if (icon != null) {
        float scale;
        int width = icon.getIntrinsicWidth();
        int height = icon.getIntrinsicHeight();
        if (width > this.mMaxIconSize) {
            scale = ((float) this.mMaxIconSize) / ((float) width);
            width = this.mMaxIconSize;
            height = (int) (((float) height) * scale);
        }
        if (height > this.mMaxIconSize) {
            scale = ((float) this.mMaxIconSize) / ((float) height);
            height = this.mMaxIconSize;
            width = (int) (((float) width) * scale);
        }
        icon.setBounds(0, 0, width, height);
    }
    setCompoundDrawables(icon, null, null, null);
    updateTextButtonVisibility();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:22,代碼來源:ActionMenuItemView.java

示例5: drawable2Bitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        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;

    Bitmap bitmap = Bitmap.createBitmap(w, h, config);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);

    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:zhou-you,項目名稱:RxEasyHttp,代碼行數:20,代碼來源:ACache.java

示例6: onDraw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    Drawable[] drawables = getCompoundDrawables();
    if (drawables != null) {
        Drawable drawableLeft = drawables[0];
        if (drawableLeft != null) {
            float textWidth = getPaint().measureText(getText().toString());
            int drawablePadding = getCompoundDrawablePadding();
            int drawableWidth = 0;
            drawableWidth = drawableLeft.getIntrinsicWidth();
            float bodyWidth = textWidth + drawableWidth + drawablePadding;
            canvas.translate((getWidth() - bodyWidth) / 11 * 5, 0);
        }
    }
    super.onDraw(canvas);
}
 
開發者ID:zwmlibs,項目名稱:BookReader-master,代碼行數:17,代碼來源:DrawableCenterButton.java

示例7: drawable2Bitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的長寬
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的顏色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立對應 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立對應 bitmap 的畫布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 內容畫到畫布中
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:20,代碼來源:ACache.java

示例8: emoticonDisplay

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static void emoticonDisplay(Context context, Spannable spannable, int emoticon, int fontSize, int start, int end) {
    Drawable drawable = getDrawable(context, emoticon);
    if (drawable != null) {
        int itemHeight;
        int itemWidth;
        if (fontSize == WRAP_DRAWABLE) {
            itemHeight = drawable.getIntrinsicHeight();
            itemWidth = drawable.getIntrinsicWidth();
        } else {
            itemHeight = fontSize;
            itemWidth = fontSize;
        }
        drawable.setBounds(0, 0, itemHeight, itemWidth);
        EmoticonSpan imageSpan = new EmoticonSpan(drawable);
        spannable.setSpan(imageSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:QQFilter.java

示例9: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static Bitmap drawableToBitmap(@NonNull Drawable drawable) {
    Bitmap bitmap;
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); // Single color bitmap will be created of 1x1 pixel
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.RGB_565);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:21,代碼來源:DrawableUtils.java

示例10: drawable2Bitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的長寬
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的顏色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
            ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立對應 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立對應 bitmap 的畫布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 內容畫到畫布中
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:zwmlibs,項目名稱:BookReader-master,代碼行數:21,代碼來源:ACache.java

示例11: drawable2Bitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * drawable轉bitmap
 *
 * @param drawable drawable對象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        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, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:27,代碼來源:ConvertUtils.java

示例12: setDivider

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Sets the drawable that will be drawn between each item in the list. If
 * the drawable does not have an intrinsic height, you should also call
 * {@link #setDividerHeight(int)}
 * 
 * @param divider
 *            The drawable to use.
 */
public void setDivider(Drawable divider) {
	if (LOG_ENABLED) {
		Log.i(LOG_TAG, "setDivider: " + divider);
	}

	if (divider != null) {
		mDividerWidth = divider.getIntrinsicWidth();
	} else {
		mDividerWidth = 0;
	}
	mDivider = divider;
	mDividerIsOpaque = divider == null || divider.getOpacity() == PixelFormat.OPAQUE;
	requestLayout();
	invalidate();
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:24,代碼來源:HListView.java

示例13: setTargetAspectRatio

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * This method sets aspect ratio for crop bounds.
 * If {@link #SOURCE_IMAGE_ASPECT_RATIO} value is passed - aspect ratio is calculated
 * based on current image width and height.
 *
 * @param targetAspectRatio - aspect ratio for image crop (e.g. 1.77(7) for 16:9)
 */
public void setTargetAspectRatio(float targetAspectRatio) {
    final Drawable drawable = getDrawable();
    if (drawable == null) {
        mTargetAspectRatio = targetAspectRatio;
        return;
    }

    if (targetAspectRatio == SOURCE_IMAGE_ASPECT_RATIO) {
        mTargetAspectRatio = drawable.getIntrinsicWidth() / (float) drawable.getIntrinsicHeight();
    } else {
        mTargetAspectRatio = targetAspectRatio;
    }

    setupCropBounds();
    postInvalidate();
}
 
開發者ID:BrandonVargas,項目名稱:AndroidOCRFforID,代碼行數:24,代碼來源:CropImageView.java

示例14: createBitmapFromRes

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public static Bitmap createBitmapFromRes( int nResID, Context context, boolean bScaleToPO2 ) {

        // pull in the resource
        Bitmap bitmap = null;

        Drawable image = context.getResources().getDrawable( nResID );
        float density = context.getResources().getDisplayMetrics().density;

        int originalWidth = (int)(image.getIntrinsicWidth() / density);
        int originalHeight = (int)(image.getIntrinsicHeight() / density);

        int powWidth = OGLChart.getNextHighestPO2( originalWidth );
        int powHeight = OGLChart.getNextHighestPO2( originalHeight );

        if ( bScaleToPO2 ) {
            image.setBounds( 0, 0, powWidth, powHeight );
        } else {
            image.setBounds( 0, 0, originalWidth, originalHeight );
        }

        // Create an empty, mutable bitmap
        bitmap = Bitmap.createBitmap( powWidth, powHeight, Bitmap.Config.ARGB_8888 );
        // get a canvas to paint over the bitmap
        Canvas canvas = new Canvas( bitmap );
        bitmap.eraseColor(0);

        image.draw( canvas ); // draw the image onto our bitmap
        
        return bitmap;
    }
 
開發者ID:woshiwpa,項目名稱:SmartMath,代碼行數:31,代碼來源:ActivityChartDemon.java

示例15: getScrollPosition

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Return the point at the center of the zoomed image. The PointF coordinates range
 * in value between 0 and 1 and the focus point is denoted as a fraction from the left
 * and top of the view. For example, the top left corner of the image would be (0, 0).
 * And the bottom right corner would be (1, 1).
 * @return PointF representing the scroll position of the zoomed image.
 */
public PointF getScrollPosition() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return null;
    }
    int drawableWidth = drawable.getIntrinsicWidth();
    int drawableHeight = drawable.getIntrinsicHeight();

    PointF point = transformCoordTouchToBitmap(viewWidth / 2, viewHeight / 2, true);
    point.x /= drawableWidth;
    point.y /= drawableHeight;
    return point;
}
 
開發者ID:lueans,項目名稱:LueansRead,代碼行數:21,代碼來源:TouchImageView.java


注:本文中的android.graphics.drawable.Drawable.getIntrinsicWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。