package com.example.fan.text1;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.TextureView;
import android.widget.FrameLayout;
import android.widget.Toast;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.TextureView;
import android.widget.FrameLayout;
import android.widget.Toast;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class text1 extends AppCompatActivity implements TextureView.SurfaceTextureListener {
InterstitialAd mInterstitialAd;
private TextureView myTexture;
private Camera mCamera;
private Camera mCamera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text1);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text1);
if (!this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
ActivityCompat.requestPermissions(this, new String[] {android.Manifest.permission.READ_CONTACTS, android.Manifest.permission.WRITE_CONTACTS, android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.CAMERA},1);
//Snackbar.make(mView, "沒照相機", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
ActivityCompat.requestPermissions(this, new String[] {android.Manifest.permission.READ_CONTACTS, android.Manifest.permission.WRITE_CONTACTS, android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.CAMERA},1);
//Snackbar.make(mView, "沒照相機", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
//=============方法一
myTexture = new TextureView(this);
myTexture.setSurfaceTextureListener(this);
setContentView(myTexture);
myTexture.setSurfaceTextureListener(this);
setContentView(myTexture);
//============方法二
setContentView(R.layout.activity_text1);
myTexture = (TextureView) findViewById(R.id.textureView);
myTexture.setSurfaceTextureListener(this);
setContentView(R.layout.activity_text1);
myTexture = (TextureView) findViewById(R.id.textureView);
myTexture.setSurfaceTextureListener(this);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
// Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
//myTexture.setLayoutParams(new FrameLayout.LayoutParams(previewSize.width, previewSize.height, Gravity.CENTER));
mCamera = Camera.open();
try {
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
} catch (IOException ioe) {
// Something bad happened
}
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
} catch (IOException ioe) {
// Something bad happened
}
myTexture.setAlpha(1.0f);//透明度,變化範圍是0.0f到1.0f之間,一般用於漸變動畫。
myTexture.setRotation(90.0f);//轉向
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mCamera.stopPreview();
mCamera.release();
return true;
}
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mCamera.stopPreview();
mCamera.release();
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
}
}
沒有留言:
張貼留言
影片的問題請留在影片的留言區裡。
部落格不會另外通知給我,所以很難發現你有留言。