本文整理汇总了Java中android.graphics.Canvas.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.getWidth方法的具体用法?Java Canvas.getWidth怎么用?Java Canvas.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawScale
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawScale(Canvas canvas) {
//计算开始和结束刻画时候的刻度
float start = (getScrollX() - mDrawOffset) / mParent.getInterval() + mParent.getMinScale();
float end = (getScrollX() + canvas.getWidth() + mDrawOffset) / mParent.getInterval() + mParent.getMinScale();
for (float i = start; i <= end; i++) {
//将要刻画的刻度转化为位置信息
float locationX = (i - mParent.getMinScale()) * mParent.getInterval();
if (i >= mParent.getMinScale() && i <= mParent.getMaxScale()) {
if (i % mCount == 0) {
canvas.drawLine(locationX, 0, locationX, mParent.getBigScaleLength(), mBigScalePaint);
canvas.drawText(RulerStringUtil.resultValueOf(i,mParent.getFactor()), locationX, mParent.getTextMarginHead(), mTextPaint);
} else {
canvas.drawLine(locationX, 0, locationX, mParent.getSmallScaleLength(), mSmallScalePaint);
}
}
}
//画轮廓线
canvas.drawLine(getScrollX(), 0, getScrollX() + canvas.getWidth(), 0, mOutLinePaint);
}
示例2: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas c) {
int w = c.getWidth();
int h = c.getHeight();
if (mMemInfo == null) return;
final int N = mMemInfo.pss.length;
final float barStep = (float) w / N;
final float barWidth = Math.max(1, barStep);
final float scale = (float) h / mMemInfo.max;
int i;
float x;
for (i=0; i<N; i++) {
x = i * barStep;
c.drawRect(x, h - scale * mMemInfo.pss[i], x + barWidth, h, pssPaint);
c.drawRect(x, h - scale * mMemInfo.uss[i], x + barWidth, h, ussPaint);
}
x = mMemInfo.head * barStep;
c.drawRect(x, 0, x + barWidth, h, headPaint);
}
示例3: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(backgroundColor);
if (colorWheel != null)
canvas.drawBitmap(colorWheel, 0, 0, null);
if (currentColorCircle != null) {
float maxRadius = canvas.getWidth() / 2f - STROKE_RATIO * (1f + ColorWheelRenderer.GAP_PERCENTAGE);
float size = maxRadius / density / 2;
colorWheelFill.setColor(Color.HSVToColor(currentColorCircle.getHsvWithLightness(this.lightness)));
colorWheelFill.setAlpha((int) (alpha * 0xff));
canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * STROKE_RATIO, selectorStroke1);
canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size * (1 + (STROKE_RATIO - 1) / 2), selectorStroke2);
canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, alphaPatternPaint);
canvas.drawCircle(currentColorCircle.getX(), currentColorCircle.getY(), size, colorWheelFill);
}
}
示例4: drawBackground
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawBackground(Canvas canvas, Rect frame) {
int width = canvas.getWidth();
int height = canvas.getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(OPAQUE);
canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
}
}
示例5: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
canvas.drawColor(0);
int width = 0;
if(mWidth != 0){
width = mWidth;
}else {
width = canvas.getWidth();
}
float radius = width / 2f;
strokeWidth = radius / 12f;
this.strokePaint.setStrokeWidth(strokeWidth);
this.fillPaint.setColor(getColor());
canvas.drawCircle(radius, radius, radius - strokeWidth * 1.5f, fillBackPaint);
canvas.drawCircle(radius, radius, radius - strokeWidth * 1.5f, fillPaint);
canvas.drawCircle(radius, radius, radius - strokeWidth, strokePaint);
}
示例6: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
if (isInEditMode()) {
return;
}
Rect frame = mFrameRect;
if (frame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// 绘制焦点框外边的暗色背景
mPaint.setColor(mMaskColor);
canvas.drawRect(0, 0, width, frame.top, mPaint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, mPaint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, mPaint);
canvas.drawRect(0, frame.bottom + 1, width, height, mPaint);
drawFocusRect(canvas, frame);
drawAngle(canvas, frame);
drawText(canvas, frame);
drawLaser(canvas, frame);
}
示例7: render
import android.graphics.Canvas; //导入方法依赖的package包/类
public void render(Canvas canvas) {
if (this.canvas == null) return;
float scaleX = 1.0F * canvas.getWidth() / this.canvas.getWidth();
float scaleY = 1.0F * canvas.getHeight() / this.canvas.getHeight();
Matrix matrix = new Matrix();
matrix.setScale(scaleX, scaleY);
for (int i = 0; i < this.historyPointer; i++) {
Path path = this.pathLists.get(i);
Paint paint = this.paintLists.get(i);
Path scaledPath = new Path();
path.transform(matrix, scaledPath);
Paint scaledPaint = new Paint(paint);
scaledPaint.setStrokeWidth(scaledPaint.getStrokeWidth() * scaleX);
canvas.drawPath(scaledPath, scaledPaint);
}
}
示例8: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void onDraw(Canvas canvas) {
// Load the bitmap
loadBitmap();
// Check if image isn't null
if (image == null)
return;
if (!isInEditMode()) {
canvasSize = canvas.getWidth();
if (canvas.getHeight() < canvasSize) {
canvasSize = canvas.getHeight();
}
}
// circleCenter is the x or y of the view's center
// radius is the radius in pixels of the cirle to be drawn
// paint contains the shader that will texture the shape
int circleCenter = (int) (canvasSize - (borderWidth * 2)) / 2;
// Draw Border
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth - (shadowRadius + shadowRadius / 2), paintBorder);
// Draw CircularImageView
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - (shadowRadius + shadowRadius / 2), paint);
}
示例9: dispatchDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void dispatchDraw(Canvas canvas) {
if (mBitmap == null) {
mBitmap = createNewBitmap(canvas);
mCanvas.setBitmap(mBitmap);
} else if (mBitmap.getWidth() != canvas.getWidth() ||
mBitmap.getHeight() != canvas.getHeight()) {
mBitmap.recycle();
mBitmap = createNewBitmap(canvas);
mCanvas.setBitmap(mBitmap);
}
super.dispatchDraw(mCanvas);
canvas.drawBitmap(mBitmap, 0, 0, null);
}
示例10: update
import android.graphics.Canvas; //导入方法依赖的package包/类
private void update(Canvas c) {
canvas = c;
if (c != null) {
width = c.getWidth();
height = c.getHeight();
if (mIsHardwareAccelerated) {
mMaximumBitmapWidth = getMaximumBitmapWidth(c);
mMaximumBitmapHeight = getMaximumBitmapHeight(c);
}
}
}
示例11: drawBar
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void drawBar(Canvas barCanvas) {
int width = barCanvas.getWidth();
int height = barCanvas.getHeight();
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
int l = Math.max(2, width / 256);
for (int x = 0; x <= width; x += l) {
hsv[2] = (float) x / (width - 1);
barPaint.setColor(Color.HSVToColor(hsv));
barCanvas.drawRect(x, 0, x + l, height, barPaint);
}
}
示例12: drawMultilineText
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawMultilineText(Canvas canvas, String text, float x, float y, TextPaint paint, Layout.Alignment aligment) {
final float lineHeight = paint.getTextSize();
float lineY = y;
for (CharSequence line : text.split("\n")) {
canvas.save();
{
final float lineWidth = (int) paint.measureText(line.toString());
float lineX = x;
if (aligment == Layout.Alignment.ALIGN_CENTER) {
lineX -= lineWidth / 2f;
}
if (lineX < 0) {
lineX = 0;
}
final float right = lineX + lineWidth;
if (right > canvas.getWidth()) {
lineX = canvas.getWidth() - lineWidth - settings.paddingCorners;
}
canvas.translate(lineX, lineY);
final StaticLayout staticLayout = new StaticLayout(line, paint, (int) lineWidth, aligment, 1.0f, 0, false);
staticLayout.draw(canvas);
lineY += lineHeight;
}
canvas.restore();
}
}
示例13: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isRippleEnabled && progress > 0) {
if (rippleX == 0 && rippleY == 0) {
rippleX = canvas.getWidth() / 2;
rippleY = canvas.getHeight() / 2;
}
Bitmap ripple = getRipple();
if (ripple != null)
canvas.drawBitmap(ripple, 0, 0, paint);
}
}
示例14: renderViewToCanvas
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* Renders this SVG document to a Canvas using the specified view defined in
* the document.
* <p>
* A View is an special element in a SVG documents that describes a
* rectangular area in the document. Calling this method with a
* {@code viewId} will result in the specified view being positioned and
* scaled to the viewport. In other words, use {@link #renderToPicture()} to
* render the whole document, or use this method instead to render just a
* part of it.
* <p>
* If the {@code <view>} could not be found, nothing will be drawn.
*
* @param viewId
* the id of a view element in the document that defines which
* section of the document is to be visible.
* @param canvas
* the canvas to which the document should be rendered.
* @param viewPort
* the bounds of the area on the canvas you want the SVG
* rendered, or null for the whole canvas.
*/
public void renderViewToCanvas(String viewId, Canvas canvas, RectF viewPort) {
SvgObject obj = this.getElementById(viewId);
if (obj == null)
return;
if (!(obj instanceof SVG.View))
return;
SVG.View view = (SVG.View) obj;
if (view.viewBox == null) {
Log.w(TAG, "View element is missing a viewBox attribute.");
return;
}
Box svgViewPort;
if (viewPort != null) {
svgViewPort = Box.fromLimits(viewPort.left, viewPort.top,
viewPort.right, viewPort.bottom);
} else {
svgViewPort = new Box(0f, 0f, (float) canvas.getWidth(),
(float) canvas.getHeight());
}
SVGAndroidRenderer renderer = new SVGAndroidRenderer(canvas,
svgViewPort, this.renderDPI);
renderer.renderDocument(this, view.viewBox, view.preserveAspectRatio,
true);
}
示例15: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* Draws the overlay with its associated graphic objects.
*/
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
synchronized (lock) {
if ((previewWidth != 0) && (previewHeight != 0)) {
widthScaleFactor = (float) canvas.getWidth() / (float) previewWidth;
heightScaleFactor = (float) canvas.getHeight() / (float) previewHeight;
}
for (Graphic graphic : graphics) {
graphic.draw(canvas);
}
}
}