您的位置:首页 > 移动开发 > Android开发

TextureView官方Demo

2015-12-03 11:17 411 查看
package com.*.*.activity;

import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.TextureView;

import com.<span style="font-family: Arial, Helvetica, sans-serif;">*.*</span><span style="font-family: Arial, Helvetica, sans-serif;">.R;</span>

import java.io.IOException;

import butterknife.Bind;

public class TextureActivity extends BaseActivity implements TextureView.SurfaceTextureListener
{

@Bind(R.id.toolbar)
Toolbar mToolbar;
@Bind(R.id.texture)
TextureView mTexture;
private Camera mCamera;

@Override
protected int getContentViewLayoutID()
{
return R.layout.activity_texture;
}

@Override
protected void initView()
{
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if (null == actionBar)
{
return;
}
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle("Texture");
mTexture.setSurfaceTextureListener(this);
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
mCamera = Camera.open();

try
{
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
//            mTexture.setAlpha(1.0f);
mTexture.setRotation(90.0f);//控件旋转,90.0f代表顺时针旋转90度,因为正常的位图是逆时针90度的,ORZ...
} catch (IOException ioe)
{
// Something bad happened
}
}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
{
// Ignored, Camera does all the work for us
}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
{
mCamera.stopPreview();
mCamera.release();
return true;
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface)
{
// Invoked every time there's a new Camera preview frame
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android 官方 demo