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


Java Canvas.getWidth方法代碼示例

本文整理匯總了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);

}
 
開發者ID:totond,項目名稱:BooheeRuler,代碼行數:22,代碼來源:TopHeadRuler.java

示例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);
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:23,代碼來源:WeightWatcher.java

示例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);
	}
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:19,代碼來源:ColorPickerView.java

示例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);
    }
}
 
開發者ID:Jusenr,項目名稱:zxing_qrcode_demo,代碼行數:18,代碼來源:ViewfinderView.java

示例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);
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:19,代碼來源:CircleColorDrawable.java

示例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);
}
 
開發者ID:simplezhli,項目名稱:Tesseract-OCR-Scanner,代碼行數:25,代碼來源:ScannerFinderView.java

示例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);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:23,代碼來源:CanvasView.java

示例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);
}
 
開發者ID:h4h13,項目名稱:RetroMusicPlayer,代碼行數:26,代碼來源:CircularImageView.java

示例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);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:16,代碼來源:ScreenshotingFrameLayout.java

示例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);
        }
    }
}
 
開發者ID:lisnstatic,項目名稱:live_master,代碼行數:12,代碼來源:AndroidDisplayer.java

示例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);
	}
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:LightnessSlider.java

示例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();
    }

}
 
開發者ID:florent37,項目名稱:android-slidr,代碼行數:31,代碼來源:Slidr.java

示例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);
    }
}
 
開發者ID:TheAndroidMaster,項目名稱:Buttons,代碼行數:16,代碼來源:Button.java

示例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);
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:53,代碼來源:SVG.java

示例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);
    }
  }
}
 
開發者ID:square,項目名稱:kind-photo-bot,代碼行數:18,代碼來源:GraphicOverlay.java


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