本文整理匯總了Java中android.graphics.Canvas.save方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.save方法的具體用法?Java Canvas.save怎麽用?Java Canvas.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(@NonNull Canvas canvas, CharSequence text,
int start, int end, float x,
int top, int y, int bottom, @NonNull 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();
}
} else {
if (mVerticalAlignment == ALIGN_BASELINE) {
transY -= paint.getFontMetricsInt().descent;
}
}
canvas.translate(x, transY);
d.draw(canvas);
canvas.restore();
}
示例2: drawTopLeftTip
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 左上角畫梯形
* @param canvas
* @param realWaist 腰長
*/
private void drawTopLeftTip(Canvas canvas, float realWaist) {
path.moveTo(this.realStartDisH, 0);
path.lineTo(this.realStartDisH + realWaist, 0);
path.lineTo(0, this.realStartDisH + realWaist);
path.lineTo(0, this.realStartDisH);
path.close();
canvas.drawPath(path, backPaint);
canvas.save();
Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
float dis = (waistDis /2 + this.startDisH) /2;
float disY = dis - (fontMetrics.bottom + fontMetrics.top) / 2f;
canvas.rotate(-45, dis, dis);
canvas.drawText(tipContent, dis, disY, textPaint);
canvas.rotate(45, dis, dis);
canvas.restore();
}
示例3: addLogoToQRCode
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 添加logo到二維碼圖片上
*
* @param src
* @param logo
* @return
*/
private static Bitmap addLogoToQRCode(Bitmap src, Bitmap logo) {
if (src == null || logo == null) {
return src;
}
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
} catch (Exception e) {
bitmap = null;
}
return bitmap;
}
示例4: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void draw(Canvas canvas) {
int saveCount = canvas.save();
mTempBounds.set(mBounds);
mTempBounds.inset(mStrokeInset, mStrokeInset);
mTempBounds.inset(mTempBounds.width() * (1.0f - mScale) / 2.0f, mTempBounds.width() * (1.0f - mScale) / 2.0f);
canvas.rotate(mGroupRotation, mTempBounds.centerX(), mTempBounds.centerY());
mPaint.setColor(mColor);
mPaint.setAlpha((int) (MAX_ALPHA * mScale));
mPaint.setStrokeWidth(mStrokeWidth * mScale);
if (mSwipeDegrees != 0) {
for (int i = 0; i < mGearCount; i++) {
canvas.drawArc(mTempBounds, mStartDegrees + DEGREE_360 / mGearCount * i, mSwipeDegrees, false, mPaint);
}
}
canvas.restoreToCount(saveCount);
}
示例5: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, Position position) {
canvas.drawPath(mPath, (flags & SELECTED) != 0
? mSelectedPaint : mBackgroundPaint);
canvas.drawPath(mPath, (flags & SELECTED) != 0
? mSelectedPaint : mOutlinePaint);
if (mView != null) {
int state = canvas.save();
canvas.translate(mView.getLeft(), mView.getTop());
// keep icons "upright" if we get displayed on TOP position
if (position != Position.TOP) {
canvas.rotate(mStart + mSweep / 2 - 270);
} else {
canvas.rotate(mStart + mSweep / 2 - 90);
}
canvas.translate(-mView.getWidth() / 2, -mView.getHeight() / 2);
mView.draw(canvas);
canvas.restoreToCount(state);
}
}
示例6: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, Paint paint) {
float rWidth=getWidth()/5;
float rHeight=getHeight()/5;
for (int i = 0; i < 2; i++) {
canvas.save();
canvas.translate(translateX[i], translateY[i]);
canvas.rotate(degrees);
canvas.scale(scaleFloat,scaleFloat);
RectF rectF=new RectF(-rWidth/2,-rHeight/2,rWidth/2,rHeight/2);
canvas.drawRect(rectF,paint);
canvas.restore();
}
}
示例7: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, Paint paint) {
float circleSpacing=4;
float radius=(Math.min(getWidth(),getHeight())-circleSpacing*2)/6;
float x = getWidth()/ 2-(radius*2+circleSpacing);
float y=getHeight() / 2;
for (int i = 0; i < 3; i++) {
canvas.save();
float translateX=x+(radius*2)*i+circleSpacing*i;
canvas.translate(translateX, y);
canvas.scale(scaleFloats[i], scaleFloats[i]);
canvas.drawCircle(0, 0, radius, paint);
canvas.restore();
}
}
示例8: onDrawMainUpView
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 重寫了繪製的函數.
*/
@Override
public boolean onDrawMainUpView(Canvas canvas)
{
canvas.save();
if (!isDrawUpRect)
{
// 繪製陰影.
onDrawShadow(canvas);
// 繪製最上層的邊框.
onDrawUpRect(canvas);
}
// 繪製焦點子控件.
if (mFocusView != null && (!isDrawUpRect && isInDraw))
{
onDrawFocusView(canvas);
}
//
if (isDrawUpRect)
{
// 繪製陰影.
onDrawShadow(canvas);
// 繪製最上層的邊框.
onDrawUpRect(canvas);
}
canvas.restore();
return true;
}
示例9: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
if(!mClipOutlines){
super.draw(canvas);
return;
}
final int state = canvas.save();
mRevealPath.reset();
mRevealPath.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW);
canvas.clipPath(mRevealPath);
super.draw(canvas);
canvas.restoreToCount(state);
}
示例10: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override public void draw(@NonNull Canvas canvas) {
super.draw(canvas);
int width = getWidth();
int height = getHeight();
if (insets != null && insetForeground != null) {
int sc = canvas.save();
canvas.translate(getScrollX(), getScrollY());
// Top
tempRect.set(0, 0, width, insets.top);
insetForeground.setBounds(tempRect);
insetForeground.draw(canvas);
// Bottom
tempRect.set(0, height - insets.bottom, width, height);
insetForeground.setBounds(tempRect);
insetForeground.draw(canvas);
// Left
tempRect.set(0, insets.top, insets.left, height - insets.bottom);
insetForeground.setBounds(tempRect);
insetForeground.draw(canvas);
// Right
tempRect.set(width - insets.right, insets.top, width, height - insets.bottom);
insetForeground.setBounds(tempRect);
insetForeground.draw(canvas);
canvas.restoreToCount(sc);
}
}
示例11: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
float x, int top, int y, int bottom, Paint paint) {
Drawable drawable = getDrawable();
canvas.save();
int transY = 0;
transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
canvas.translate(x, transY);
drawable.draw(canvas);
canvas.restore();
}
示例12: drawRightEdge
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawRightEdge(DepthLayout dl, Canvas canvas, float[] src) {
float[] dst = new float[]{dl.getTopRight().x, dl.getTopRight().y, dl.getTopRightBack().x, dl.getTopRightBack().y, dl.getBottomRightBack().x, dl.getBottomRightBack().y, dl.getBottomRight().x, dl.getBottomRight().y};
int count = canvas.save();
matrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
canvas.concat(matrix);
drawRectancle(dl, canvas);
drawShadow(dl.getTopRight(), dl.getBottomRight(), -180f, canvas, dl);
canvas.restoreToCount(count);
}
示例13: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.concat(matrix);
wrapped.draw(canvas);
canvas.restore();
}
示例14: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int bitmapWidth = bitmap.getWidth();
int bitmapHeight = bitmap.getHeight();
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
int x = centerX - bitmapWidth / 2;
int y = centerY - bitmapHeight / 2;
// 第一遍繪製:上半部分
canvas.save();
canvas.clipRect(0, 0, getWidth(), centerY);
canvas.drawBitmap(bitmap, x, y, paint);
canvas.restore();
// 第二遍繪製:下半部分
canvas.save();
if (degree < 90) {
canvas.clipRect(0, centerY, getWidth(), getHeight());
} else {
canvas.clipRect(0, 0, getWidth(), centerY);
}
camera.save();
camera.rotateX(degree);
canvas.translate(centerX, centerY);
camera.applyToCanvas(canvas);
canvas.translate(-centerX, -centerY);
camera.restore();
canvas.drawBitmap(bitmap, x, y, paint);
canvas.restore();
}
示例15: drawItems
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* Draws items
*
* @param canvas the canvas for drawing
*/
private void drawItems(Canvas canvas) {
canvas.save();
int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
canvas.translate(PADDING, -top + scrollingOffset);
itemsLayout.draw(canvas);
canvas.restore();
}