下面列出了android.graphics.Camera#setLocation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public RotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RotateView);
BitmapDrawable bitmapDrawable = (BitmapDrawable) array.getDrawable(R.styleable.RotateView_viewBackgound2);
array.recycle();
if (bitmapDrawable != null) {
bitmap = bitmapDrawable.getBitmap();
byte[] bytes = BitmapUtil.bitmap2Bytes(bitmap);
bitmap = BitmapUtil.resizeBitmapBytes(bytes);
}else {
bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
}
camera = new Camera();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
DisplayMetrics metrics = getResources().getDisplayMetrics();
float newZ = -metrics.density * 6;
camera.setLocation(0, 0, newZ);
}
public ShuttersConsumer() {
setReleaseMode(RELEASE_MODE_AUTO_OPEN_CLOSE);
mCamera = new Camera();
mCamera.setLocation(0,0, -20);
mPaint = new Paint();
}
protected void applyTransformation(Transformation t) {
final Matrix m = t.getMatrix();
final float w = mWidth;
final float h = mHeight;
final float pX = mPivotX;
final float pY = mPivotY;
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();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
camera.setLocation(mCameraX, mCameraY, mCameraZ);
}
if (mTranslationZ != 0) {
camera.translate(0, 0, mTranslationZ);
}
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);
t.setAlpha(mAlpha);
}