android.graphics.Camera 仿3D效果

本文介绍了Android中使用android.graphics.Camera类实现2D物体在3D空间中的移动和旋转的方法,通过实例展示了如何利用该类的不同功能,如旋转、平移等来创建立体视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/imdxt1986/article/details/7023868

在Android SDK中有两种Camera classes,一个是 android.hardware.Camera,这是用来操控相机功能的类。另一个是 android.graphics.Camera,这个类别能帮我们做些什么事呢?

Camera就像一个摄像机,一个物体在原地不动,然后我们带着这个摄像机四处移动,在摄像机里面呈现出来的画面,就会有立体感,就可以从各个角度观看这个物体。
        它有旋转、平移的一系列方法,实际上都是在改变一个Matrix对象,一系列操作完毕之后,我们得到这个Matrix,然后画我们的物体,就可以了。

android.graphics.Camera 是一个可以让你将 2D 物件在 3D 空间中移动,并将在其移动后的结果画在屏幕上的类别。

打开api说明文件

 

  1. //Public Constructors   

   2.   Camera()  

       创建一个新的摄像头,空的转换

   3. //Public Methods  

   4.   void  applyToCanvas(Canvas canvas)  

       计算对应当前转换矩阵,并将其应用到指定的画布上。

   5.   float  dotWithNormal(float dx, float dy, float dz)  

   6.   void  getMatrix(Matrix matrix)  

计算对应当前转换矩阵,并将其复制到所提供的矩阵对象。

   7.   void  restore()  

 

Restores the saved state, if any.
恢复保存的状态,如果有的话。

 

8.  void rotate(float x, float y, float z)    

 

Applies a rotation transform around all three axis.
适用于所有三个轴旋转变换。

 

8.   void  rotateX(float deg)  

 

Applies a rotation transform around the X axis.
适用于绕X轴旋转变换。

 

   9.   void  rotateY(float deg)  

 

Applies a rotation transform around the Y axis.
适用于绕Y轴旋转变换。

 

  10.   void  rotateZ(float deg)  

Applies a rotation transform around the Z axis.

适用于绕Z轴旋转变换。

  11.   void  save()  

 

Saves the camera state.
12. setLocation(float x, float y, float z)
Sets the location of the camera.
设置摄像头的位置。

 

  13.   void  translate(float x, float y, float z)  

 

Applies a translation transform on all three axis.
适用于所有三个轴的翻译转换。

 

在 Android ,要做出 3D 的效果,你当然可以用 OpenGL 的函式。不过,如果你需要更快的显示速度,或者只是要做个简单的 3D 特效,

那千万不要忘了这个 android.graphics.Camera。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值