最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程調(diào)用Camera和相冊功能詳解

 更新時間:2017年02月27日 11:02:25   作者:Jacob-wj  
這篇文章主要介紹了Android編程調(diào)用Camera和相冊功能,結(jié)合實例形式分析了Android的拍照及相冊調(diào)用功能相關(guān)實現(xiàn)技巧與操作注意事項,需要的朋友可以參考下

本文實例講述了Android編程調(diào)用Camera和相冊功能。分享給大家供大家參考,具體如下:

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <Button
    android:id="@+id/button_cameraButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="拍照" />
  <Button
    android:id="@+id/button_photoButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="相冊" />
  <ImageView
    android:id="@+id/imageview_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:src="@drawable/ic_launcher" />
</LinearLayout>

activity:

package com.wj.cameratest;
import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class CameraShowActivity extends Activity {
  private ImageView mImageView;
  private Button mButtonCamera;
  private Button mButtonPhoto;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera_show);
    mImageView = (ImageView) this.findViewById(R.id.imageview_preview);
    mButtonCamera = (Button) this.findViewById(R.id.button_cameraButton);
    mButtonPhoto = (Button) this.findViewById(R.id.button_photoButton);
    mButtonCamera.setOnClickListener(new OnClickListener() { //打開Camera
      @Override
      public void onClick(View v) {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(new File(Environment
                .getExternalStorageDirectory(), "camera.jpg")));
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
        startActivityForResult(intent, 10);
      }
    });
    mButtonPhoto.setOnClickListener(new OnClickListener() { //獲取相冊
      @Override
      public void onClick(View v) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX",1);
        intent.putExtra("aspectY",1);
        intent.putExtra("outputX", 80);
        intent.putExtra("outputY", 80);
        intent.putExtra("return-data",true);
        startActivityForResult(intent, 11);
      }
    });
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 10 && resultCode == Activity.RESULT_OK) {
      this.mImageView.setImageDrawable(Drawable.createFromPath(new File(
          Environment.getExternalStorageDirectory(), "camera.jpg")
          .getAbsolutePath()));
      System.out.println("data-->"+data);
    }else if (requestCode == 11 && resultCode ==Activity.RESULT_OK) {
      System.out.println("data2-->"+data);
    }
  }
}

Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.wj.cameratest"
  android:versionCode="1"
  android:versionName="1.0" >
  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-feature android:name="android.hardware.camera" />
  <uses-feature android:name="android.hardware.camera.autofocus" />
  <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
      android:name=".CameraShowActivity"
      android:label="@string/title_activity_camera_show" >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
</manifest>

android 調(diào)用相冊里的圖片并返回

Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true);
startActivityForResult(intent, 0);

在原來的Activity中如下獲取選到的圖片:

@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 System.out.println(resultCode);
 Bitmap cameraBitmap = (Bitmap) data.getExtras().get("data");
 super.onActivityResult(requestCode, resultCode, data);
 }

PS:關(guān)于AndroidManifest.xml文件相關(guān)屬性功能可參考本站在線工具:

Android Manifest功能與權(quán)限描述大全:
http://tools.jb51.net/table/AndroidManifest

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android拍照與圖片處理技巧總結(jié)》、《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • 詳談android界面之間數(shù)據(jù)的傳遞

    詳談android界面之間數(shù)據(jù)的傳遞

    下面小編就為大家?guī)硪黄斦刟ndroid界面之間數(shù)據(jù)的傳遞。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Android中的ViewPager視圖滑動切換類的入門實例教程

    Android中的ViewPager視圖滑動切換類的入門實例教程

    Android中ViewPager通常與Fragments組件共同使用來實現(xiàn)視圖切換功能,本文就帶大家一起來學(xué)習(xí)Android中的ViewPager視圖滑動切換類的入門實例教程:
    2016-06-06
  • Android自定義控件實現(xiàn)帶文字提示的SeekBar

    Android自定義控件實現(xiàn)帶文字提示的SeekBar

    這篇文章主要給大家介紹了關(guān)于Android自定義控件實現(xiàn)帶文字提示的SeekBar的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容功能

    Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容功能

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Android測試方法總結(jié)

    Android測試方法總結(jié)

    在這篇文章中我們給大家總結(jié)了Android測試方法以及需要注意的地方,有興趣的朋友參考學(xué)習(xí)下。
    2018-07-07
  • Android基于Service的音樂播放器

    Android基于Service的音樂播放器

    這篇文章主要為大家詳細(xì)介紹了Android基于Service的音樂播放器,本文開發(fā)一個基于Service的音樂播放器,音樂由后臺運行的Service負(fù)責(zé)播放,感興趣的小伙伴們可以參考一下
    2016-08-08
  • 不可不知的Android strings.xml那些事

    不可不知的Android strings.xml那些事

    相信 strings.xml 已經(jīng)是大家在 Android 開發(fā)中最熟悉的文件之一了,但其實它也有很多需要注意的地方和一些小技巧,知道了這些可以讓你的 Android 應(yīng)用更加規(guī)范易用,大家來看看吧
    2016-08-08
  • Android實現(xiàn)音頻錄音與播放

    Android實現(xiàn)音頻錄音與播放

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)音頻錄音與播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android滾輪選擇時間控件使用詳解

    Android滾輪選擇時間控件使用詳解

    這篇文章主要為大家詳細(xì)介紹了Android滾輪選擇時間控件使用,滾輪選擇選擇數(shù)值、選擇字符串,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android 在程序運行時申請權(quán)限的實例講解

    Android 在程序運行時申請權(quán)限的實例講解

    下面小編就為大家分享一篇Android 在程序運行時申請權(quán)限的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01

最新評論

娱乐| 应用必备| 红河县| 福泉市| 滁州市| 工布江达县| 十堰市| 吉安市| 陕西省| 永城市| 靖安县| 四子王旗| 玉屏| 阿勒泰市| 大同市| 福鼎市| 黎城县| 张家港市| 全南县| 天津市| 建水县| 汶上县| 托克逊县| 贡山| 黄龙县| 神池县| 怀宁县| 邵阳县| 哈巴河县| 调兵山市| 临城县| 莱阳市| 元谋县| 丹寨县| 赫章县| 宜君县| 博客| 肇源县| 无锡市| 博野县| 互助|