android 調用系統網路攝影機

來源:互聯網
上載者:User

在開發android 應用的時候我們經常需要用到網路攝影機來進行拍照或者是錄製視頻,這裡介紹一種最簡單的方法:調用系統網路攝影機來拍照,並將照片儲存起來

啟動網路攝影機的方法:

startActivityForResult(new Intent("android.media.action.IMAGE_CAPTURE"), TAKE_PICTURE);

拍攝成功後接收參數的接收方法我們只需要重寫

protected void onActivityResult(int requestCode, int resultCode, Intent data)方法即可

如:

final int TAKE_PICTURE = 1;protected void onActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == TAKE_PICTURE) {if (resultCode == RESULT_OK) {Bitmap bm = (Bitmap) data.getExtras().get("data");imgPhoto.setImageBitmap(bm);// ??¨ª?????¨º??¨²ImageView¨º¨¨ª?¨¦?¡ê?private// ¡ä?¡ä|?D??¡ä?¡ä¡é?¡§¨º?¡¤?¡ä??¨²sdCardExit = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);// ImageView img;if (sdCardExit) {myRecAudioDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/custom_picture");if (!myRecAudioDir.exists()) {myRecAudioDir.mkdir();}} else {mMakeTextToast("¡ä?¡ä¡é?¡§2?¡ä??¨²", true);}try {File f = File.createTempFile(strTempFile, ".jpg",myRecAudioDir);BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));photoPath=f.getPath();/* 2¨¦¨??1??¡Áa¦Ì¦Ì¡¤?¡¤¡§ */bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);/* ¦Ì¡Â¨?flush()¡¤?¡¤¡§¡ê??¨¹D?BufferStream */bos.flush();/* ?¨¢¨º?OutputStream */bos.close();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}}
拍攝效果如:
 
返回結果如:
 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.