本文整理汇总了Java中android.graphics.Canvas.drawRoundRect方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawRoundRect方法的具体用法?Java Canvas.drawRoundRect怎么用?Java Canvas.drawRoundRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawRoundRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContentDrawable
import android.graphics.Canvas; //导入方法依赖的package包/类
private Drawable createContentDrawable(int width, int height) {
int radius = height / 2;
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setDither(true);
paint.setShader(createGradient(width, height));
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
if(!isFilled) {
Paint background = new Paint();
background.setAntiAlias(true);
background.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
background.setColor(mBackgroundColor);
int innerRadius = (height - mStroke) / 2;
canvas.drawRoundRect(new RectF(mStroke, mStroke, width - mStroke, height - mStroke),
innerRadius, innerRadius, background);
}
return new BitmapDrawable(getResources(), bitmap);
}
示例2: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float tempWidth = getWidth();
if (getWidth() < getHeight()) {
tempWidth = getHeight();
}
mTextRectF.set(0, 0, tempWidth, getHeight());
canvas.drawRoundRect(mTextRectF, getHeight() / 2, getHeight() / 2, mPaint);
//居中drawText
int centerY = (int) (mTextRectF.centerY() - mFontMetricsTop / 2 - mFontMetricsBottom / 2);
canvas.drawText(mDrawText, mTextRectF.centerX(), centerY, mTextPaint);
}
示例3: getRoundedSquareBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
static Bitmap getRoundedSquareBitmap(Drawable drawable, int color) {
float radius = 250.0f;
Bitmap bitmap = drawableToBitmap(drawable);
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例4: getTweetImage
import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap getTweetImage(String url) {
byte[] image_b = getImageByte(url);
Bitmap image;
if (image_b != null) {
image = BitmapFactory.decodeByteArray(image_b, 0, image_b.length);
} else {
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.pessoa_foto_default);
}
Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
Canvas canvas = new Canvas(imageRounded);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), 12, 12, paint);
return imageRounded;
}
示例5: getCircleBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 获取圆形图片
*
* @param bitmap 源bitmap
* @return 圆形bitmap
*/
public static Bitmap getCircleBitmap(Bitmap bitmap) {
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(outBitmap);
float roundSize;
roundSize = Math.min(bitmap.getHeight(), bitmap.getWidth()) / 2f;
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.WHITE);
RectF rectF = new RectF(0, 0, roundSize * 2, roundSize * 2);
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
canvas.drawRoundRect(rectF, roundSize, roundSize, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, new Rect(0, 0, Math.min(bitmap.getHeight(), bitmap.getWidth()), Math.min(bitmap.getHeight(), bitmap.getWidth())), paint);
return outBitmap;
}
示例6: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(BACKGROUND_COLOR);
int width = getWidth();
int height = getHeight();
for (int i = 0; i < 2; i++) {
rects.add((float) Math.random() * width);
rects.add((float) Math.random() * height);
}
colors.add(0xff000000 | (int) (0xffffff * Math.random()));
for (int i = 0; i < rects.size() / 4; i++) {
paint.setColor(colors.get(i));
canvas.drawRoundRect(
rects.get(i * 4 ),
rects.get(i * 4 + 1),
rects.get(i * 4 + 2),
rects.get(i * 4 + 3),
40, 40, paint);
}
if (rects.size() < 400) postInvalidateDelayed(20);
}
示例7: toRoundCorner
import android.graphics.Canvas; //导入方法依赖的package包/类
/**将图片改为圆角类型
* @param bitmap
* @param pixels
* @return
*/
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例8: drawIndicatorLine
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawIndicatorLine(Canvas canvas, int offset, ITrendData trendData) {
String textIndicator = trendData == null ? "00:00 --/--" : trendData.popTextInfo();
float offsetLineY = getBezierY(mControlPoints, offset);
mChartIndicatorPaint.setColor(trendData == null ? Color.argb(32, 255, 255, 255) : trendData.levelColor());
mChartIndicatorPaint.setStyle(Paint.Style.FILL);
mChartIndicatorPaint.setAntiAlias(true);
/**
* 气泡区域
*/
mRectIndicator.left = offset;
mRectIndicator.right = mRectIndicator.left + mIndicatorWidth;
mRectIndicator.bottom = offsetLineY;
mRectIndicator.top = mRectIndicator.bottom - mIndicatorHeight;
canvas.drawRoundRect(mRectIndicator, dp12, dp12, mChartIndicatorPaint);
//遮住左下角的半圆区域
mRectIndicator.top = mRectIndicator.top + mRectIndicator.height() / 2;
mRectIndicator.right = mRectIndicator.left + mRectIndicator.height();
canvas.drawRect(mRectIndicator, mChartIndicatorPaint);
float textWidth = mWhiteTextPaint.measureText(textIndicator);
//text position for Y axis
float textX;
float textY;
textX = offset + (mIndicatorWidth / 2 - textWidth / 2);
textY = mRectIndicator.bottom - mIndicatorHeight / 2 - mWhiteTextPaintHeight / 2;
canvas.drawText(textIndicator,
textX,
textY,
mWhiteTextPaint);
}
示例9: drawOtherBottomRightRoundRect
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius,
paint);
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius,
paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
}
示例10: drawText
import android.graphics.Canvas; //导入方法依赖的package包/类
public void drawText(ImageView imageView, String t2) {
// ImageView myImageView =
Bitmap myBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.RGB_565);
Paint myPaint = new Paint();
myPaint.setColor(Color.BLUE);
myPaint.setAntiAlias(true);
myPaint.setTextSize(80);
int x1 = 10;
int y1 = 80;
int x2 = 20;
int y2 = 20;
// Create mContext new image bitmap and attach a brand new canvas to it
Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);
Canvas tempCanvas = new Canvas(tempBitmap);
// Draw the image bitmap into the cavas
tempCanvas.drawBitmap(myBitmap, 0, 0, null);
// Draw everything else you want into the canvas, in this example mContext
// rectangle with rounded edges
tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myPaint);
tempCanvas.drawText(t2.substring(0, 1).toUpperCase(), x1, y1, myPaint);
// Attach the canvas to the ImageView
imageView.setImageDrawable(new BitmapDrawable(getResources(), tempBitmap));
}
示例11: drawDiagonalFromTopRightRoundRect
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius,
mRadius, paint);
canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom),
mRadius, mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint);
}
示例12: drawDiagonalFromTopLeftRoundRect
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter),
mRadius, mRadius, paint);
canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius,
mRadius, paint);
canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint);
canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint);
}
示例13: drawTargetWeightPath
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawTargetWeightPath(Canvas drawCanvas) {
float currentLeft = 0.0f;
float currentRight = 0.0f;
float target = this.targetWeight;
float rectPadding = (float) ChartUtils.dp2px(this.density, 2);
prepareWeightLinePaint();
Viewport currentViewport = this.computator.getCurrentViewport();
if (currentViewport != null) {
currentLeft = currentViewport.left;
currentRight = currentViewport.right;
}
float rawX1 = this.computator.computeRawX(currentLeft);
float rawX2 = this.computator.computeRawX(currentRight);
float y = this.computator.computeRawY(target);
Path path1 = new Path();
path1.moveTo(rawX1, y);
path1.lineTo(rawX2, y);
drawCanvas.drawPath(path1, this.weightLinePaint);
String targetStr = "目标: " + target + "kg";
float textWidth = this.weightStrPaint.measureText(targetStr);
float textX = ((rawX1 + rawX2) / 2.0f) - (textWidth / 2.0f);
float textY = y + (getTextHeight() / aj.hA);
this.weightLinePaint.setStyle(Style.FILL);
float corner = (float) ChartUtils.dp2px(this.density, 3);
drawCanvas.drawRoundRect(new RectF((float) ((int) (textX - rectPadding)), (float) ((int) ((y - (getTextHeight() / 2.0f)) - rectPadding)), (float) ((int) ((textX + textWidth) + rectPadding)), (float) ((int) (((getTextHeight() / 2.0f) + y) + rectPadding))), corner, corner, this.weightLinePaint);
drawCanvas.drawText(targetStr, textX, textY, this.weightStrPaint);
}
示例14: drawChartRect
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawChartRect(Canvas canvas, int position) {
ChartRect chartRect = mChartRectList.get(position);
canvas.save();
mChartPaint.setColor(chartRect.color);
RectF rectChart = chartRect.rectChart;
canvas.clipRect(rectChart.left, rectChart.top, rectChart.right, rectChart.bottom - roundRadius, Region.Op.INTERSECT);
if (position < mCurrentTimePosition) {
mChartPaint.setAlpha(102);
} else {
mChartPaint.setAlpha(255);
}
canvas.drawRoundRect(rectChart, roundRadius, roundRadius, mChartPaint);
canvas.restore();
}
示例15: drawHuePanel
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawHuePanel(Canvas canvas) {
final Rect rect = hueRect;
if (BORDER_WIDTH_PX > 0) {
borderPaint.setColor(borderColor);
canvas.drawRect(rect.left - BORDER_WIDTH_PX,
rect.top - BORDER_WIDTH_PX,
rect.right + BORDER_WIDTH_PX,
rect.bottom + BORDER_WIDTH_PX,
borderPaint);
}
if (hueBackgroundCache == null) {
hueBackgroundCache = new BitmapCache();
hueBackgroundCache.bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Config.ARGB_8888);
hueBackgroundCache.canvas = new Canvas(hueBackgroundCache.bitmap);
int[] hueColors = new int[(int) (rect.height() + 0.5f)];
// Generate array of all colors, will be drawn as individual lines.
float h = 360f;
for (int i = 0; i < hueColors.length; i++) {
hueColors[i] = Color.HSVToColor(new float[]{h, 1f, 1f});
h -= 360f / hueColors.length;
}
// Time to draw the hue color gradient,
// its drawn as individual lines which
// will be quite many when the resolution is high
// and/or the panel is large.
Paint linePaint = new Paint();
linePaint.setStrokeWidth(0);
for (int i = 0; i < hueColors.length; i++) {
linePaint.setColor(hueColors[i]);
hueBackgroundCache.canvas.drawLine(0, i, hueBackgroundCache.bitmap.getWidth(), i, linePaint);
}
}
canvas.drawBitmap(hueBackgroundCache.bitmap, null, rect, null);
Point p = hueToPoint(hue);
RectF r = new RectF();
r.left = rect.left - sliderTrackerOffsetPx;
r.right = rect.right + sliderTrackerOffsetPx;
r.top = p.y - (sliderTrackerSizePx / 2);
r.bottom = p.y + (sliderTrackerSizePx / 2);
canvas.drawRoundRect(r, 2, 2, hueAlphaTrackerPaint);
}