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


Java Drawable.draw方法代碼示例

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


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

示例1: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Drawable轉Bitmap方法
 *
 * @param drawable
 * @return
 */
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);
    } 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:l465659833,項目名稱:Bigbang,代碼行數:29,代碼來源:ImageBlurUtil.java

示例2: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void draw(@NonNull final Canvas canvas, final CharSequence text,
                 final int start, final int end, final float x,
                 final int top, final int y, final int bottom, @NonNull final Paint paint) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    canvas.save();
    final float fontHeight = paint.getFontMetrics().descent - paint.getFontMetrics().ascent;
    int transY = bottom - rect.bottom;
    if (rect.height() < fontHeight) { // this is the fucking code which I waste 3 days
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            transY -= (fontHeight - rect.height()) / 2;
        } else if (mVerticalAlignment == ALIGN_TOP) {
            transY -= fontHeight - rect.height();
        }
    }
    canvas.translate(x, transY);
    d.draw(canvas);
    canvas.restore();
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:23,代碼來源:SpanUtils.java

示例3: getBitmapFromDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (OutOfMemoryError e) {
        return null;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:CircleImageView.java

示例4: onDraw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {

    int canvasWidth = canvas.getWidth();

    int canvasHeight = canvas.getHeight();

    if (adapter != null && !adapter.isEmpty()) {
        Target.Level current = target.getCurrentLevel();
        if (current != null) {
            for (int position = current.getPosition(); position < maxNumberOfLevels; position++) {
                // draw always from the first drawable to the last
                levelListDrawable.setLevel(position - current.getPosition());
                Drawable drawable = levelListDrawable.getCurrent();
                computeDrawingBounds(canvasWidth, canvasHeight, target.getLevelAt(position).getSizePercent());
                drawable.setBounds(drawingBounds);
                drawable.draw(canvas);
            }
        }
    }
}
 
開發者ID:tsalik,項目名稱:target-layout,代碼行數:22,代碼來源:TargetLayout.java

示例5: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private 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:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:IndicatorView.java

示例6: drawableToBitmap

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

  Bitmap bitmap;
  int width = Math.max(drawable.getIntrinsicWidth(), 2);
  int height = Math.max(drawable.getIntrinsicHeight(), 2);
  try {
    bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
  } catch (Exception e) {
    e.printStackTrace();
    Log.w(TAG, "Failed to create bitmap from drawable!");
    bitmap = null;
  }

  return bitmap;
}
 
開發者ID:weimin96,項目名稱:shareNote,代碼行數:22,代碼來源:RoundedDrawable.java

示例7: onDraw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    final Drawable drawable = getDrawable();
    if (drawable != null) {
        canvas.save();
        canvas.translate(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        canvas.rotate(degrees);
        final int intrinsicWidth = drawable.getIntrinsicWidth();
        final int intrinsicHeight = drawable.getIntrinsicHeight();
        drawable.setBounds(-intrinsicWidth / 2, -intrinsicHeight / 2, intrinsicWidth / 2, intrinsicHeight / 2);
        drawable.draw(canvas);
        canvas.restore();
    }

    degrees += 10;

    if (isLoading) {
        mChoreographer.postFrameCallback(this);
    }
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:21,代碼來源:LoadingImageView.java

示例8: draw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
public void draw(Canvas c) {
    super.draw(c);
    final boolean isLayoutRtl = isLayoutRtlSupport();
    Drawable shadowDrawable;
    if (isLayoutRtl) {
        shadowDrawable = mShadowDrawableRight;
    } else {
        shadowDrawable = mShadowDrawableLeft;
    }

    final View shadowView = getChildCount() > 1 ? getChildAt(1) : null;
    if (shadowView == null || shadowDrawable == null) {
        // No need to draw a shadow if we don't have one.
        return;
    }

    final int top = shadowView.getTop();
    final int bottom = shadowView.getBottom();

    final int shadowWidth = shadowDrawable.getIntrinsicWidth();
    final int left;
    final int right;
    if (isLayoutRtlSupport()) {
        left = shadowView.getRight();
        right = left + shadowWidth;
    } else {
        right = shadowView.getLeft();
        left = right - shadowWidth;
    }

    shadowDrawable.setBounds(left, top, right, bottom);
    shadowDrawable.draw(c);
}
 
開發者ID:chemickypes,項目名稱:Glitchy,代碼行數:35,代碼來源:SideMenu.java

示例9: getBitmapDraw

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap getBitmapDraw(Drawable drawable, boolean isThumb) {
    if (drawable == null) {
        return null;
    }
    int width;
    int height;
    int maxRange = IndicatorUtils.dp2px(mContext, CUSTOM_DRAWABLE_MAX_LIMITED_WIDTH);
    int intrinsicWidth = drawable.getIntrinsicWidth();
    if (intrinsicWidth > maxRange) {
        if (isThumb) {
            width = p.mThumbSize;
        } else {
            width = p.mTickSize;
        }
        height = getHeightByRatio(drawable, width);

        if (width > maxRange) {
            width = maxRange;
            height = getHeightByRatio(drawable, width);
        }
    } else {
        width = drawable.getIntrinsicWidth();
        height = drawable.getIntrinsicHeight();
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
開發者ID:warkiz,項目名稱:IndicatorSeekBar,代碼行數:32,代碼來源:IndicatorSeekBar.java

示例10: onDrawKeyBackground

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
protected void onDrawKeyBackground(@Nonnull final Key key, @Nonnull final Canvas canvas,
        @Nonnull final Drawable background) {
    final int keyWidth = key.getDrawWidth();
    final int keyHeight = key.getHeight();
    final int bgWidth, bgHeight, bgX, bgY;
    if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)
            // HACK: To disable expanding normal/functional key background.
            && !key.hasCustomActionLabel()) {
        final int intrinsicWidth = background.getIntrinsicWidth();
        final int intrinsicHeight = background.getIntrinsicHeight();
        final float minScale = Math.min(
                keyWidth / (float)intrinsicWidth, keyHeight / (float)intrinsicHeight);
        bgWidth = (int)(intrinsicWidth * minScale);
        bgHeight = (int)(intrinsicHeight * minScale);
        bgX = (keyWidth - bgWidth) / 2;
        bgY = (keyHeight - bgHeight) / 2;
    } else {
        final Rect padding = mKeyBackgroundPadding;
        bgWidth = keyWidth + padding.left + padding.right;
        bgHeight = keyHeight + padding.top + padding.bottom;
        bgX = -padding.left;
        bgY = -padding.top;
    }
    final Rect bounds = background.getBounds();
    if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
        background.setBounds(0, 0, bgWidth, bgHeight);
    }
    canvas.translate(bgX, bgY);
    background.draw(canvas);
    canvas.translate(-bgX, -bgY);
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:32,代碼來源:KeyboardView.java

示例11: getBitmapFromDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLOR_DRAWABLE_DIMENSION, COLOR_DRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:tylersuehr7,項目名稱:chips-input-layout,代碼行數:28,代碼來源:CircleImageView.java

示例12: getBitmapFromDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
static Bitmap getBitmapFromDrawable(Drawable drawable) {
  if (drawable instanceof BitmapDrawable) {
    return ((BitmapDrawable) drawable).getBitmap();
  } else {
    Bitmap 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:mapbox,項目名稱:mapbox-plugins-android,代碼行數:13,代碼來源:Utils.java

示例13: generateIconBitmaps

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap[] generateIconBitmaps(Drawable drawable) {
  if (drawable == null)
    return null;
  Bitmap 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 generateIconBitmaps(Bitmap.createScaledBitmap(bitmap, iconSize, iconSize, false));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:MaterialAutoCompleteTextView.java

示例14: drawableToBitmap

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
 * Convert a drawable object into a Bitmap.
 * @param drawable Drawable to extract a Bitmap from.
 * @return A Bitmap created from the drawable parameter.
 */
public Bitmap drawableToBitmap(Drawable drawable) {
	if (drawable == null)   // Don't do anything without a proper drawable
		return null;
	else if (drawable instanceof BitmapDrawable) {  // Use the getBitmap() method instead if BitmapDrawable
		Log.i(TAG, "Bitmap drawable!");
		return ((BitmapDrawable) drawable).getBitmap();
	}

	int intrinsicWidth = drawable.getIntrinsicWidth();
	int intrinsicHeight = drawable.getIntrinsicHeight();

	if (!(intrinsicWidth > 0 && intrinsicHeight > 0))
		return null;

	try {
		// Create Bitmap object out of the drawable
		Bitmap bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
		drawable.draw(canvas);
		return bitmap;
	} catch (OutOfMemoryError e) {
		// Simply return null of failed bitmap creations
		Log.e(TAG, "Encountered OutOfMemoryError while generating bitmap!");
		return null;
	}
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:33,代碼來源:CircularImageView.java

示例15: getBitmapFromDrawable

import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap getBitmapFromDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }

    try {
        Bitmap bitmap;

        if (drawable instanceof ColorDrawable) {
            bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
開發者ID:coderwjq,項目名稱:ZhaZhaShop,代碼行數:28,代碼來源:CircleImageView.java


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