Skip to content

Commit

Permalink
Merge pull request hzuapps#576 from chenqiuwen/master
Browse files Browse the repository at this point in the history
#1 hzuapps#88 hzuapps#89 hzuapps#90 实验1、2、3、4
  • Loading branch information
zengsn committed Apr 30, 2016
2 parents 1624e13 + 043401d commit aba0731
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package edu.hzuapps.androidworks.homeworks.net1314080903105;

import java.io.IOException;

import android.hardware.Camera;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
/*整个预览的流程是建立一个surface,
获取surface得控制器surfaceholder,
设立surface的窗口previewdisplay,
最后开始预览startpreview。
当然最后还要添加相机相关的权限。*/
public class Net1314080903105MainActivity extends Activity {
private SurfaceView mView=null; //是建立一个surface
private SurfaceHolder mHolder=null;
private Camera mCamera=null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_net131408903105);
mView=(SurfaceView)this.findViewById(R.id.surfaceView1);
mHolder=mView.getHolder(); //获取surface得控制器surfaceHolder
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
// mHolder.setFixedSize(1, 700); // 设置Surface分辨率
// mHolder.setSizeFromLayout();
// mHolder.setKeepScreenOn(true);// 屏幕常亮
mHolder.addCallback(new Callback(){

@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
mCamera=Camera.open(1); //若要升级增加摄像头选择则应该设置try,catch
try {
mCamera.setPreviewDisplay(mHolder); //设立surface的窗口PreviewDisplay
mCamera.setDisplayOrientation(90); //设置摄像头角度,以后若有需要可以用来调试手机横竖显示
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mCamera.startPreview();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
mCamera.startPreview();
mCamera.release();
}});
}


}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_main_net131408903105.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Net1314080903105MainActivity" >

<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit aba0731

Please sign in to comment.