android.graphics.Camera.restore()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中android.graphics.Camera.restore()方法的一些代码示例,展示了Camera.restore()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Camera.restore()方法的具体详情如下:
包路径:android.graphics.Camera
类名称:Camera
方法名:restore

Camera.restore介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

private void transformMatrix(Matrix m, View view) {
  final float w = view.getWidth();
  final float h = view.getHeight();
  final boolean hasPivot = mHasPivot;
  final float pX = hasPivot ? mPivotX : w / 2f;
  final float pY = hasPivot ? mPivotY : h / 2f;
  final float rX = mRotationX;
  final float rY = mRotationY;
  final float rZ = mRotationZ;
  if ((rX != 0) || (rY != 0) || (rZ != 0)) {
    final Camera camera = mCamera;
    camera.save();
    camera.rotateX(rX);
    camera.rotateY(rY);
    camera.rotateZ(-rZ);
    camera.getMatrix(m);
    camera.restore();
    m.preTranslate(-pX, -pY);
    m.postTranslate(pX, pY);
  }
  final float sX = mScaleX;
  final float sY = mScaleY;
  if ((sX != 1.0f) || (sY != 1.0f)) {
    m.postScale(sX, sY);
    final float sPX = -(pX / w) * ((sX * w) - w);
    final float sPY = -(pY / h) * ((sY * h) - h);
    m.postTranslate(sPX, sPY);
  }
  m.postTranslate(mTranslationX, mTranslationY);
}

代码示例来源:origin: stackoverflow.com

Camera mCamera;
 mCamera.save();
 mCamera.rotateY(distance/40f); //you should divide by the parent's width so your       rotation values are 0>=rotation >= MAX_ROTATION
 mCamera.getMatrix(matrix);
 mCamera.restore();

代码示例来源:origin: JingYeoh/FragmentRigger

@Override
 protected void applyTransformation(float interpolatedTime, Transformation t) {
  Camera camera = new Camera();
  camera.save();

  // 设置camera动作为绕Y轴旋转
  // 总共旋转180度,因此计算在每个补间时间点interpolatedTime的角度即为两着相乘
//    camera.rotateX(deg * interpolatedTime);
  camera.rotateY(180 * interpolatedTime);
//    camera.rotateZ(180 * interpolatedTime);
//
  // 根据camera动作产生一个matrix,赋给Transformation的matrix,以用来设置动画效果
  Matrix matrix = t.getMatrix();
  camera.getMatrix(matrix);

  camera.restore();
  //经过以下平移,才能以view的中心点进行翻转
  matrix.preTranslate(-view.getWidth() / 2, -view.getHeight() / 2);
  matrix.postTranslate(view.getWidth() / 2, view.getHeight() / 2);
 }
}

代码示例来源:origin: Ramotion/folding-cell-android

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
  final Camera camera = mCamera;
  final Matrix matrix = t.getMatrix();
  final float fromDegrees = mFromDegrees;
  final float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
  camera.save();
  camera.rotateX(degrees);
  camera.getMatrix(matrix);
  camera.restore();
  matrix.preTranslate(-mCenterX, -mCenterY);
  matrix.postTranslate(mCenterX, mCenterY);
}

代码示例来源:origin: Bilibili/DanmakuFlameMaster

private int saveCanvas(BaseDanmaku danmaku, Canvas canvas, float left, float top) {
  camera.save();
  if (locationZ !=0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
    camera.setLocation(0, 0, locationZ);
  }
  camera.rotateY(-danmaku.rotationY);
  camera.rotateZ(-danmaku.rotationZ);
  camera.getMatrix(matrix);
  matrix.preTranslate(-left, -top);
  matrix.postTranslate(left , top);
  camera.restore();
  int count = canvas.save();
  canvas.concat(matrix);
  return count;
}

代码示例来源:origin: Yalantis/Side-Menu.Android

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
  final float fromDegrees = mFromDegrees;
  float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
  final float centerX = mCenterX;
  final float centerY = mCenterY;
  final Camera camera = mCamera;
  final Matrix matrix = t.getMatrix();
  camera.save();
  camera.rotateY(degrees);
  camera.getMatrix(matrix);
  camera.restore();
  matrix.preTranslate(-centerX, -centerY);
  matrix.postTranslate(centerX, centerY);
}

代码示例来源:origin: jdsjlzx/LRecyclerView

@Override
public void draw(Canvas canvas, Paint paint) {
  mMatrix.reset();
  mCamera.save();
  mCamera.rotateX(rotateX);
  mCamera.rotateY(rotateY);
  mCamera.getMatrix(mMatrix);
  mCamera.restore();
  mMatrix.preTranslate(-centerX(), -centerY());
  mMatrix.postTranslate(centerX(), centerY());
  canvas.concat(mMatrix);
  Path path=new Path();
  path.moveTo(getWidth()/5,getHeight()*4/5);
  path.lineTo(getWidth()*4/5, getHeight()*4/5);
  path.lineTo(getWidth()/2,getHeight()/5);
  path.close();
  canvas.drawPath(path, paint);
}

代码示例来源:origin: AigeStudio/WheelPicker

mCamera.rotateX(degree);
mCamera.getMatrix(mMatrixRotate);
mCamera.restore();
mMatrixRotate.preTranslate(-transX, -transY);
mMatrixRotate.postTranslate(transX, transY);
mCamera.translate(0, 0, computeDepth((int) degree));
mCamera.getMatrix(mMatrixDepth);
mCamera.restore();
mMatrixDepth.preTranslate(-transX, -transY);
mMatrixDepth.postTranslate(transX, transY);

代码示例来源:origin: jdsjlzx/LRecyclerView

@Override
public void draw(Canvas canvas, Paint paint) {
  mMatrix.reset();
  mCamera.save();
  mCamera.rotateX(degress);
  mCamera.getMatrix(mMatrix);
  mCamera.restore();
  mMatrix.preTranslate(-centerX(), -centerY());
  mMatrix.postTranslate(centerX(), centerY());
  canvas.concat(mMatrix);
  float radius=getWidth()/10;
  canvas.drawCircle(getWidth()/4,radius*2,radius,paint);
  canvas.drawCircle(getWidth()*3/4,radius*2,radius,paint);
  canvas.drawCircle(radius,getHeight()-2*radius,radius,paint);
  canvas.drawCircle(getWidth()/2,getHeight()-2*radius,radius,paint);
  canvas.drawCircle(getWidth()-radius,getHeight()-2*radius,radius,paint);
}

代码示例来源:origin: jdsjlzx/LRecyclerView

@Override
public void draw(Canvas canvas, Paint paint) {
  mMatrix.reset();
  mCamera.save();
  mCamera.rotateX(rotateX);
  mCamera.rotateY(rotateY);
  mCamera.getMatrix(mMatrix);
  mCamera.restore();
  mMatrix.preTranslate(-centerX(), -centerY());
  mMatrix.postTranslate(centerX(), centerY());
  canvas.concat(mMatrix);
  canvas.drawRect(new RectF(getWidth()/5,getHeight()/5,getWidth()*4/5,getHeight()*4/5),paint);
}

代码示例来源:origin: stackoverflow.com

camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);

代码示例来源:origin: JingYeoh/FragmentRigger

@Override
 protected void applyTransformation(float interpolatedTime, Transformation t) {
  final float fromDegrees = mFromDegrees;
  float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

  final float centerX = mCenterX;
  final float centerY = mCenterY;
  final Camera camera = mCamera;
  final Matrix matrix = t.getMatrix();
  camera.save();
  if (mReverse) {
   camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
  } else {
   camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
  }
  camera.rotateY(degrees);
  camera.getMatrix(matrix);
  camera.restore();

  matrix.preTranslate(-centerX, -centerY);
  matrix.postTranslate(centerX, centerY);
 }
}

代码示例来源:origin: ImmortalZ/StereoView

private void drawScreen(Canvas canvas, int i, long drawingTime) {
  int curScreenY = mHeight * i;
  //屏幕中不显示的部分不进行绘制
  if (getScrollY() + mHeight < curScreenY) {
    return;
  }
  if (curScreenY < getScrollY() - mHeight) {
    return;
  }
  float centerX = mWidth / 2;
  float centerY = (getScrollY() > curScreenY) ? curScreenY + mHeight : curScreenY;
  float degree = mAngle * (getScrollY() - curScreenY) / mHeight;
  if (degree > 90 || degree < -90) {
    return;
  }
  canvas.save();
  mCamera.save();
  mCamera.rotateX(degree);
  mCamera.getMatrix(mMatrix);
  mCamera.restore();
  mMatrix.preTranslate(-centerX, -centerY);
  mMatrix.postTranslate(centerX, centerY);
  canvas.concat(mMatrix);
  drawChild(canvas, getChildAt(i), drawingTime);
  canvas.restore();
}

代码示例来源:origin: ybq/Android-SpinKit

@Override
public void draw(Canvas canvas) {
  int tx = getTranslateX();
  tx = tx == 0 ? (int) (getBounds().width() * getTranslateXPercentage()) : tx;
  int ty = getTranslateY();
  ty = ty == 0 ? (int) (getBounds().height() * getTranslateYPercentage()) : ty;
  canvas.translate(tx, ty);
  canvas.scale(getScaleX(), getScaleY(), getPivotX(), getPivotY());
  canvas.rotate(getRotate(), getPivotX(), getPivotY());
  if (getRotateX() != 0 || getRotateY() != 0) {
    mCamera.save();
    mCamera.rotateX(getRotateX());
    mCamera.rotateY(getRotateY());
    mCamera.getMatrix(mMatrix);
    mMatrix.preTranslate(-getPivotX(), -getPivotY());
    mMatrix.postTranslate(getPivotX(), getPivotY());
    mCamera.restore();
    canvas.concat(mMatrix);
  }
  drawSelf(canvas);
}

代码示例来源:origin: com.nineoldandroids/library

private void transformMatrix(Matrix m, View view) {
  final float w = view.getWidth();
  final float h = view.getHeight();
  final boolean hasPivot = mHasPivot;
  final float pX = hasPivot ? mPivotX : w / 2f;
  final float pY = hasPivot ? mPivotY : h / 2f;
  final float rX = mRotationX;
  final float rY = mRotationY;
  final float rZ = mRotationZ;
  if ((rX != 0) || (rY != 0) || (rZ != 0)) {
    final Camera camera = mCamera;
    camera.save();
    camera.rotateX(rX);
    camera.rotateY(rY);
    camera.rotateZ(-rZ);
    camera.getMatrix(m);
    camera.restore();
    m.preTranslate(-pX, -pY);
    m.postTranslate(pX, pY);
  }
  final float sX = mScaleX;
  final float sY = mScaleY;
  if ((sX != 1.0f) || (sY != 1.0f)) {
    m.postScale(sX, sY);
    final float sPX = -(pX / w) * ((sX * w) - w);
    final float sPY = -(pY / h) * ((sY * h) - h);
    m.postTranslate(sPX, sPY);
  }
  m.postTranslate(mTranslationX, mTranslationY);
}

代码示例来源:origin: kakajika/FragmentAnimations

camera.rotateZ(-rZ);
camera.getMatrix(m);
camera.restore();
m.preTranslate(-pX, -pY);
m.postTranslate(pX, pY);

代码示例来源:origin: xenione/tab-digit

public static void translateY(Matrix matrix, float dy) {
    synchronized (camera) {
      camera.save();
      camera.translate(0, dy, 0);
      camera.getMatrix(matrix);
      camera.restore();
    }
  }
}

代码示例来源:origin: xenione/tab-digit

public static void rotateX(Matrix matrix, int alpha) {
  synchronized (camera) {
    camera.save();
    camera.rotateX(alpha);
    camera.getMatrix(matrix);
    camera.restore();
  }
}

代码示例来源:origin: xenione/tab-digit

public static void rotateZ(Matrix matrix, int alpha) {
  synchronized (camera) {
    camera.save();
    camera.rotateZ(alpha);
    camera.getMatrix(matrix);
    camera.restore();
  }
}

代码示例来源:origin: xenione/tab-digit

public static void translate(Matrix matrix, float dx, float dy, float dz) {
  synchronized (camera) {
    camera.save();
    camera.translate(dx, dy, dz);
    camera.getMatrix(matrix);
    camera.restore();
  }
}

相关文章