課程
/移動(dòng)開發(fā)
/Android
/Android攝像頭基礎(chǔ)
在CustomCamera.java文件中void capture(View view)方法里面寫什么?視頻里好像沒有展示這一塊。
2016-03-15
源自:Android攝像頭基礎(chǔ) 3-2
正在回答
這個(gè)是按鈕的點(diǎn)擊時(shí)間,里面主要是實(shí)現(xiàn)拍照功能,
? public ?void capture(View view){
? ? ? ? Camera.Parameters param=mcamera.getParameters();
? ? ? ? param.setPictureFormat(ImageFormat.JPEG);
? ? ? ? param.setPreviewSize(800,400);
? ? ? ? param.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
? ? ? ? mcamera.autoFocus(new Camera.AutoFocusCallback(){
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAutoFocus(boolean success, Camera camera) {
? ? ? ? ? ? ? ? if (success){
? ? ? ? ? ? ? ? ? ? mcamera.takePicture(null,null,mpictureCallback);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
然后在最上面加上
?private Camera.PictureCallback mpictureCallback=new Camera.PictureCallback(){
? ? ? ? @Override
? ? ? ? public void onPictureTaken(byte[] data, Camera camera) {//將拍攝數(shù)據(jù)寫入臨時(shí)文件中
? ? ? ? ? ? File temFile=new File("/sdcard/tem.png");
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? FileOutputStream fos=new FileOutputStream(temFile);
? ? ? ? ? ? ? ? fos.write(data);
? ? ? ? ? ? ? ? fos.close();
? ? ? ? ? ? ? ? Intent intent=new Intent(MainActivity.this, ResultActivity.class);
? ? ? ? ? ? ? ? intent.putExtra("picPath",temFile.getAbsolutePath());
? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? ? ? MainActivity.this.finish();
? ? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? };
彪悍大藍(lán)貓 提問(wèn)者
舉報(bào)
帶你走進(jìn)Android攝像頭的秘密花園,探索Camera的奧秘
3 回答capture點(diǎn)擊事件
1 回答點(diǎn)擊Capture拍照無(wú)法跳轉(zhuǎn)
1 回答點(diǎn)擊capture按鈕崩潰
5 回答什么我的照片沒出現(xiàn)在ImageView里面呢?
4 回答為什么我的照片無(wú)法顯示在ImageView中啊
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-03-19
這個(gè)是按鈕的點(diǎn)擊時(shí)間,里面主要是實(shí)現(xiàn)拍照功能,
? public ?void capture(View view){
? ? ? ? Camera.Parameters param=mcamera.getParameters();
? ? ? ? param.setPictureFormat(ImageFormat.JPEG);
? ? ? ? param.setPreviewSize(800,400);
? ? ? ? param.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
? ? ? ? mcamera.autoFocus(new Camera.AutoFocusCallback(){
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onAutoFocus(boolean success, Camera camera) {
? ? ? ? ? ? ? ? if (success){
? ? ? ? ? ? ? ? ? ? mcamera.takePicture(null,null,mpictureCallback);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });
? ? }
然后在最上面加上
?private Camera.PictureCallback mpictureCallback=new Camera.PictureCallback(){
? ? ? ? @Override
? ? ? ? public void onPictureTaken(byte[] data, Camera camera) {//將拍攝數(shù)據(jù)寫入臨時(shí)文件中
? ? ? ? ? ? File temFile=new File("/sdcard/tem.png");
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? FileOutputStream fos=new FileOutputStream(temFile);
? ? ? ? ? ? ? ? fos.write(data);
? ? ? ? ? ? ? ? fos.close();
? ? ? ? ? ? ? ? Intent intent=new Intent(MainActivity.this, ResultActivity.class);
? ? ? ? ? ? ? ? intent.putExtra("picPath",temFile.getAbsolutePath());
? ? ? ? ? ? ? ? startActivity(intent);
? ? ? ? ? ? ? ? MainActivity.this.finish();
? ? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? }
? ? ? ? }
? ? };