Android Media(拍照)
程式碼實現:
package com.zking.administrator.g160628_android28_playvideo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
public class CameraActivity extends AppCompatActivity {
private SurfaceView sv_camera_surface;
private Camera camera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
sv_camera_surface = (SurfaceView) findViewById(R.id.sv_camera_surface);
sv_camera_surface.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
//開啟攝像頭
camera = Camera.open();
//設定攝像引數
Camera.Parameters parameters= camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.set("jpeg-quality",100);
camera.setParameters(parameters);
//開啟預覽效果
camera.startPreview();
//將畫面展示到surfaceView
try {
camera.setPreviewDisplay(sv_camera_surface.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
}
});
}
public void takePhoto(View view){
camera.takePicture(null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap bitmap=BitmapFactory.decodeByteArray(data,0,data.length);
//時間戳
Calendar calendar=Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH);
int day=calendar.get(Calendar.DAY_OF_MONTH);
try {
FileOutputStream fos=new FileOutputStream("/mnt/sdcard/dcim/camera/G160628_"+year+(month+1)+day+"_"+System.currentTimeMillis()+".jpg");
//壓縮
bitmap.compress(Bitmap.CompressFormat.JPEG,85,fos);
camera.stopPreview();
camera.startPreview();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});
}
}
相關文章
- android 拍照Android
- Android拍照Android
- Android Media playerAndroid
- Android Camera——拍照Android
- Android Media Framework - 開篇AndroidFramework
- Android Media Framework(五)Tunnel ModeAndroidFramework
- Android呼叫攝像頭拍照Android
- Android自定義拍照實現Android
- Android 拍照新增時間水印Android
- Android 呼叫攝像頭拍照Android
- Android提供的攝像頭拍照Android
- Android Media Framework(一)OpenMAX 框架簡介AndroidFramework框架
- Android本地圖片上傳(拍照+相簿)Android地圖
- Android 拍照、選擇圖片並裁剪Android
- android 實現拍照的2種方法Android
- Android圖片(視訊)選擇器:android-media-pickerAndroid
- 照片系列之android呼叫攝像頭拍照Android
- Android開發之呼叫攝像頭拍照Android
- Android呼叫系統相簿和相機拍照Android
- Android Media Framework(三)OpenMAX API閱讀與分析AndroidFrameworkAPI
- Android Studio 呼叫Camera實現拍照功能Android
- Android呼叫攝像頭拍照並顯示照片Android
- Android7.0拍照以及使用uCrop裁剪Android
- Android 呼叫攝像頭功能【拍照與視訊】Android
- Android視訊開發進階(part3-Android的Media API)AndroidAPI
- SCSS @mediaCSS
- Android 圓形頭像 相簿和拍照裁剪選取Android
- 【Android】【opencv】實現攝像頭拍照和錄影AndroidOpenCV
- Android拍照與相機適配問題彙總Android
- Android 呼叫系統相機拍照 . 選取本地相簿Android
- Android 從本地選取圖片或者拍照填充ImageViewAndroidView
- iOS自定義拍照框拍照&裁剪(一)iOS
- Android拍照,相簿選擇圖片以及Android6.0許可權管理Android
- Android | 教你如何開發一個拍照翻譯小程式Android
- CSS media queriesCSS
- mac media serverMacServer
- Media Session APISessionAPI
- 在Android中呼叫攝像頭拍照並顯示出來Android