本文整理汇总了Java中android.graphics.Canvas.drawColor方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawColor方法的具体用法?Java Canvas.drawColor怎么用?Java Canvas.drawColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
protected void onDraw(Canvas canvas) {
if (count <= 1) {
this.setVisibility(View.GONE);
return;
}
float height = getHeight();
float radius = height * DESIGN_INDICATOR_RADIUS / DESIGN_BOTTOM_HEIGHT;
float distance = height * DESIGN_INDICATOR_DISTANCE / DESIGN_BOTTOM_HEIGHT;
float windowWidth = radius * 2 * count + distance * (count - 1);
float left = (getWidth() - windowWidth) / 2;
float cy = height / 2;
canvas.drawColor(0xffffffff);
Paint paint = new Paint();
paint.setAntiAlias(true);
for (int i = 0; i < count; i++) {
if (i == current) {
paint.setColor(0xff5d71a0);
} else {
paint.setColor(0xffafb1b7);
}
float cx = left + (radius * 2 + distance) * i;
canvas.drawCircle(cx, cy, radius, paint);
}
}
示例2: DebugImage
import android.graphics.Canvas; //导入方法依赖的package包/类
/** creates images of text for internal testing */
private static Bitmap DebugImage(String text, int width, int height) {
Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bm);
c.drawColor(Color.RED);
Paint p = new Paint();
p.setTextAlign(Paint.Align.CENTER);
p.setAntiAlias(true);
p.setColor(Color.WHITE);
p.setStyle(Paint.Style.FILL_AND_STROKE);
p.setTextSize(20);
p.setTypeface(Typeface.DEFAULT_BOLD);
float textWidth = p.measureText(text);
float newTextSize = width / textWidth * 19.5f;
p.setTextSize(newTextSize);
Rect r = new Rect();
p.getTextBounds("X", 0, 1, r);
int textHeight = r.top - r.bottom;
c.drawText(text, width / 2f, (height - textHeight) / 2f, p);
return bm;
}
示例3: onDrawComplete
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDrawComplete(Canvas canvas, int translation) {
final int contentSpaceH = v.getContentSpace();
if (v.getDirection() == StretchView.BOTTOM || v.getDirection() == StretchView.RIGHT) {
translation = -translation;
}
if (translation <= 0) return;
if (translation <= contentSpaceH) {
canvas.clipRect(rect);
final int maxAlpha = (int) (255 * 0.7);
canvas.drawColor((int) (maxAlpha * (1 - translation * 1.0f / contentSpaceH)) << 24);
}
}
示例4: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
public void draw(Canvas canvas) {
Canvas drawCanvas;
LineChartData data = this.dataProvider.getLineChartData();
if (this.softwareBitmap != null) {
drawCanvas = this.softwareCanvas;
drawCanvas.drawColor(0, Mode.CLEAR);
} else {
drawCanvas = canvas;
}
this.targetWeight = this.lineChartView.getTargetWeight();
if (this.targetWeight > 0.0f) {
drawTargetWeightPath(drawCanvas);
}
for (Line line : data.getLines()) {
if (line.hasLines()) {
if (line.isCubic()) {
drawSmoothPath(drawCanvas, line);
} else if (line.isSquare()) {
drawSquarePath(drawCanvas, line);
} else {
drawPath(drawCanvas, line);
}
}
}
if (this.softwareBitmap != null) {
canvas.drawBitmap(this.softwareBitmap, 0.0f, 0.0f, null);
}
}
示例5: drawCube
import android.graphics.Canvas; //导入方法依赖的package包/类
void drawCube(Canvas c) {
c.save();
c.translate(mCenterX, mCenterY);
c.drawColor(0xff000000);
long now = SystemClock.elapsedRealtime();
float xrot = ((float)(now - mStartTime)) / 1000;
float yrot = (0.5f - mOffset) * 2.0f;
rotateAndProjectPoints(xrot, yrot);
drawLines(c);
c.restore();
}
示例6: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw( Canvas canvas )
{
super.draw( canvas );
this.canvas = canvas;
if(background == null)
{
canvas.drawColor( Color.LTGRAY );
}
else
{
int zoom_w = (int) ( paper_width * paper_scale );
int zoom_h = (int) ( paper_height * paper_scale );
// 소스 렉트값 지정 및 타겟 렉트값 찾기
Rect source = new Rect( 0, 0, background.getWidth(), background.getHeight() );
RectF target = new RectF( offsetX, offsetY, offsetX + zoom_w, offsetY + zoom_h );
canvas.drawBitmap( background, source, target, null );
}
if ( strokes != null && strokes.size() > 0 )
{
float screen_offset_x = -paper_offsetX * paper_scale;
float screen_offset_y = -paper_offsetY * paper_scale;
Renderer.draw( canvas, strokes.toArray( new Stroke[0] ), paper_scale, screen_offset_x+offsetX, screen_offset_y+offsetY,Stroke.STROKE_TYPE_PEN );
}
}
示例7: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mBytes == null) {
return;
}
// Get the current angle all of the shapes are at
double currentAngleRadians = calcCurrentAngle();
// Draw the background
canvas.drawColor(backgroundColor);
// Draw each shape
if (showBass) {
mBassCircle.draw(canvas, bass, currentAngleRadians);
}
if (showMid) {
mMidSquare.draw(canvas, mid, currentAngleRadians);
}
if (showTreble) {
mTrebleTriangle.draw(canvas, treble, currentAngleRadians);
}
// Invalidate the view to immediately redraw
invalidate();
}
示例8: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
Canvas c = canvas;
if (mExternalSurface != null) {
try {
Rect r = new Rect();
r = canvas.getClipBounds();
int [] location = new int[2];
getLocationOnScreen(location);
r.offsetTo(location[0],location[1]);
c = mExternalSurface.lockCanvas(null);
c.save();
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
c.clipRect(r);
c.translate(location[0],location[1]);
} catch (Exception e) {
Log.d(TAG, "Can not lock canvas!!!!");
}
}
Bitmap draw = Bitmap.createScaledBitmap(mBitmap, mDrawWidth, mDrawHeight, true);
c.drawBitmap(draw, mDrawX, 0, mPaint);
draw.recycle();
if (c != canvas) {
c.restore();
mExternalSurface.unlockCanvasAndPost(c);
}
}
}
示例9: getBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
public Bitmap getBitmap() {
Bitmap result = Bitmap.createBitmap(mModeSize.width(), mModeSize.height(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.drawColor(Color.BLACK);
if (mImageOK) {
mImageDrawRect.set(getIntRect(mInputRect));
adjustCanvasAndImageRect(mModeSize.width(), mModeSize.height());
drawBitmap(canvas);
}
mLabelCollection.draw(canvas, mOutputRect, new Rect(0, 0, mModeSize.width(), mModeSize.height()));
return result;
}
示例10: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if(points.size() == 0) {
points.add(getWidth() / 2.f);
points.add(getHeight() / 2.f);
}
while(points.size() - currentIndex >= 6) {
float x1 = points.get(currentIndex);
float y1 = points.get(currentIndex + 1);
float x2 = points.get(currentIndex + 2);
float y2 = points.get(currentIndex + 3);
float x3 = points.get(currentIndex + 4);
float y3 = points.get(currentIndex + 5);
if (currentIndex == 0) path.moveTo(x1, y1);
path.cubicTo(x1, y1, x2, y2, x3, y3);
currentIndex += 6;
}
canvas.drawColor(BACKGROUND_COLOR);
canvas.drawPath(path, pathPaint);
for(int i = 0; i < points.size() / 2; i++) {
float x = points.get(i * 2 );
float y = points.get(i * 2 + 1);
canvas.drawPoint(x, y, pointsPaint);
}
}
示例11: onDrawElements
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDrawElements(Canvas canvas) {
mPaint.reset();
mPaint.setColor(hillColor);
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
clearCanvas(canvas);
canvas.drawColor(getDynamicColor());
mPaint.setAlpha(100);
mPathRear.reset();
mPathRear.moveTo(getWidth(), getHeight() - getHeight() * 1 / 7 * hillTransFactor);
mPathRear.rQuadTo(-getWidth() / 2, -20 * hillTransFactor, -getWidth(), getHeight() / 10 * hillTransFactor);
mPathRear.lineTo(0, getHeight());
mPathRear.lineTo(getWidth(), getHeight());
mPathRear.close();
canvas.drawPath(mPathRear, mPaint);
mPaint.setAlpha(255);
mPathFront.reset();
mPathFront.moveTo(0, getHeight() - getHeight() * 1 / 7 * hillTransFactor);
mPathFront.rQuadTo(getWidth() / 2, -20 * hillTransFactor, getWidth(), getHeight() / 10 * hillTransFactor);
mPathFront.lineTo(getWidth(), getHeight());
mPathFront.lineTo(0, getHeight());
mPathFront.close();
drawFan(canvas, mPathFront, 0.618f * hillTransFactor, 1f);
drawFan(canvas, mPathRear, 0.15f * hillTransFactor, 0.4f);
mPaint.reset();
mPaint.setColor(hillColor);
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawPath(mPathFront, mPaint);
mPaint.setShader(cloudShader);
cloudPath.reset();
cloudPath.addCircle(getWidth() * cloudTransFactor, getHeight() * 0.618f - cloudOffset, getHeight() / 22, Path.Direction.CW);
cloudPath.addCircle(getWidth() * cloudTransFactor, getHeight() * 0.618f, getHeight() / 22, Path.Direction.CW);
cloudPath.addCircle(getWidth() * cloudTransFactor - getHeight() / 19, getHeight() * 0.618f - cloudOffset * 2 / 3, getHeight() / 26, Path.Direction.CW);
cloudPath.addCircle(getWidth() * cloudTransFactor + getHeight() / 20, getHeight() * 0.618f - cloudOffset * 2 / 3, getHeight() / 30, Path.Direction.CW);
canvas.drawPath(cloudPath, mPaint);
}
示例12: createTestBitmap
import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap createTestBitmap() {
final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.GREEN);
return bitmap;
}
示例13: generateShortcutPreview
import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap generateShortcutPreview(
Launcher launcher, ActivityInfo info, int maxWidth, int maxHeight, Bitmap preview) {
final Canvas c = new Canvas();
if (preview == null) {
preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
c.setBitmap(preview);
} else if (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight) {
throw new RuntimeException("Improperly sized bitmap passed as argument");
} else {
// Reusing bitmap. Clear it.
c.setBitmap(preview);
c.drawColor(0, PorterDuff.Mode.CLEAR);
}
Drawable icon = mutateOnMainThread(mIconCache.getFullResIcon(info));
icon.setFilterBitmap(true);
// Draw a desaturated/scaled version of the icon in the background as a watermark
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
icon.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
icon.setAlpha((int) (255 * 0.06f));
Resources res = mContext.getResources();
int paddingTop = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
int paddingLeft = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
int paddingRight = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
icon.setBounds(paddingLeft, paddingTop,
paddingLeft + scaledIconWidth, paddingTop + scaledIconWidth);
icon.draw(c);
// Draw the final icon at top left corner.
// TODO: use top right for RTL
int appIconSize = launcher.getDeviceProfile().iconSizePx;
icon.setAlpha(255);
icon.setColorFilter(null);
icon.setBounds(0, 0, appIconSize, appIconSize);
icon.draw(c);
c.setBitmap(null);
return preview;
}
示例14: doDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
public void doDraw(Canvas c, int fps) {
if ((c==null) || (c.getWidth() == 0) || (c.getHeight() == 0)){
return;
}
if (!landscapeInitialized){
Log.d("Display", "doDraw: width = " + c.getWidth() + ", height = " + c.getHeight());
int fpsenabled = 0;
if(PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_fps", false))
fpsenabled = 1;
host.game.getBoard().invalidate();
//portraitInitialized = false;
landscapeInitialized = true;
squaresize = (int)(((c.getHeight()-1) - 2*rowOffset)/rows);
int size2 = (int)(((c.getHeight()-1) - 2*columnOffset)/(columns + 4 + host.getResources().getInteger(R.integer.padding_columns)));
if(size2 < squaresize) {
squaresize = size2;
rowOffset = (int)(((c.getHeight()-1) - squaresize*rows)/2);
} else
columnOffset = (int)(((c.getWidth()-1) - squaresize*(host.getResources().getInteger(R.integer.padding_columns)+4+columns))/2);
gridRowBorder = rowOffset + squaresize*rows;
gridColumnBorder = columnOffset + squaresize*columns;
prev_top = rowOffset;
prev_bottom = rowOffset + 4*squaresize;
prev_left = gridColumnBorder + host.getResources().getInteger(R.integer.padding_columns)*squaresize;
prev_right = prev_left + 4*squaresize;
textLeft = prev_left;
textTop = prev_bottom + 2*squaresize;
textRight = (c.getWidth()-1) - columnOffset;
textBottom = (c.getHeight()-1) - rowOffset - squaresize;
textSizeH = 1;
// Adaptive Text Size Setup
textPaint.setTextSize(textSizeH + 1);
while(textPaint.measureText("00:00:00") < (textRight - textLeft)) {
//stuff
textPaint.getTextBounds((String)"Level:32", 0, 6, textRect);
textHeight = textRect.height();
textEmptySpacing = ((textBottom - textTop) - (textLines*(textHeight + 3))) / (3 + fpsenabled);
if(textEmptySpacing < 10)
break;
textSizeH++;
textPaint.setTextSize(textSizeH + 1);
}
textPaint.setTextSize(textSizeH);
textPaint.getTextBounds((String)"Level:32", 0, 6, textRect);
textHeight = textRect.height() + 3;
textEmptySpacing = ((textBottom - textTop) - (textLines*(textHeight))) / (3 + fpsenabled);
host.controls.setPreviewRect(new Rect(prev_left,prev_top,prev_right,prev_bottom));
}
// Background
//paint.setColor(host.getResources().getColor(color.background_dark));
//c.drawRect(0, 0, c.getWidth()-1, c.getHeight()-1, paint);
c.drawColor(Color.argb(0, 0, 0, 0), android.graphics.PorterDuff.Mode.CLEAR);
host.game.getBoard().draw(columnOffset, rowOffset, squaresize, c);
drawActive(columnOffset, rowOffset, squaresize, c);
if(PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_phantom", true))
drawPhantom(columnOffset, rowOffset, squaresize, c);
drawGrid(columnOffset, rowOffset, gridColumnBorder, gridRowBorder, c);
if(host.controls.isBoardTouched())
drawTouchIndicator();
drawPreview(prev_left, prev_top, prev_right, prev_bottom, c);
drawTextFillBox(c, fps);
if(PreferenceManager.getDefaultSharedPreferences(host).getBoolean("pref_popup", true))
drawPopupText(c);
}
示例15: ClearTouchpoint
import android.graphics.Canvas; //导入方法依赖的package包/类
private void ClearTouchpoint() {
Canvas canvas = holder.lockCanvas();
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
holder.unlockCanvasAndPost(canvas);
}