Android開發之初識Camera映像採集,android映像採集

來源:互聯網
上載者:User

Android開發之初識Camera映像採集,android映像採集

/** Android開發之初識camera映像採集* 北京Android俱樂部群:167839253* Created on: 2011-8-24* Author: blueeagle* Email: liujiaxiang@gmail.com*/下面記錄一個簡單的相機的製作方法。製作相機,首先需要添加照相的許可權。添加方法是在AndroidManifest.xml檔案中添加<uses-permission android:name=” android.permission.CAMERA”>即可。其次:修改布局檔案:如下代碼所示。<textarea readonly name="code" class="html"><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >     <SurfaceView     android:id = "@+id/mySurfaceView"     android:layout_width="320px"     android:layout_height="240px">     </SurfaceView>     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     > <Button android:id="@+id/myButton"      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="開啟"/> <Button android:id="@+id/myButton2"      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="關閉"/> </LinearLayout> </LinearLayout> </textarea>再次,編輯代碼,如下所示:<textarea readonly name="code" class="java">/* *  Android開發之camera映像採集 *  MyTestCamera.java *  Created on: 2011-8-24 *  Author: blueeagle *  Email: liujiaxiang@gmail.com */ package com.blueeagle; import java.io.IOException; import android.app.Activity; import android.hardware.Camera; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.Button; public class MyTestCamera extends Activity implements SurfaceHolder.Callback{     Camera myCamera;     SurfaceView mySurfaceView;     SurfaceHolder mySurfaceHolder;     Button myButton1;     Button myButton2;     boolean isPreview = false;     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                 mySurfaceView = (SurfaceView)findViewById(R.id.mySurfaceView);         myButton1 = (Button)findViewById(R.id.myButton);         myButton2 = (Button)findViewById(R.id.myButton2);                 mySurfaceHolder = mySurfaceView.getHolder();         mySurfaceHolder.addCallback(this);         mySurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);         myButton1.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { initCamera(); }         });                myButton2.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { if(myCamera!=null&amp;&amp;isPreview){ myCamera.stopPreview(); myCamera.release(); myCamera = null; isPreview = false; } }                 });     } public void initCamera() { // TODO Auto-generated method stub if(!isPreview){ myCamera = Camera.open(); } if(myCamera !=null &amp;&amp; !isPreview){ try{ myCamera.setPreviewDisplay(mySurfaceHolder); myCamera.startPreview(); } catch(IOException e){ e.printStackTrace(); } isPreview = true; } } @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 } @Override public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub } } </textarea><br>如果在模擬器中運行,可以得到的情形。如果在真機上運行,則會開啟網路攝影機,將實際的影響顯現出來。關閉時,則定在關閉時的畫面。這樣基本可以完成了映像的採集。如果程式中對相機有要求的話,可以採用這種方式進行。<img src="http://www.bkjia.com/uploads/allimg/140902/160404I20-0.gif" alt="">這個例子只是一個小demo。供深入學習參考用。<br>

好文章 :假如你喜歡一位碼農小帥哥


android開發自訂Camera surfaceview設定

將你的預覽大小的參數設定為camera所支援的參數大小應該就沒有展開的問題了
 
android使用camera拍照然後對圖片進行編輯的問題

你是想實現不同activity之間傳值 。
可以有以下方法 :
1 sharedpreference 如果資料量大 ,不建議使用它
2 檔案儲存體 , 存進去再讀出來
3 inten 傳值 :
Intent intent = new Intent(this,xxx.class);
Bundle bundle = new Bundler();
Bundle.putString("key","value");
intent.putExtras(bundle);
startActivity(intent);

跳轉到另外activity取值 :
Bundle bundle = this.getIntent().getExtras();
bundle.getString("key");
4 建資料庫吧
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.