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

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

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

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

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="相冊(cè)" />
  <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() { //獲取相冊(cè)
      @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)用相冊(cè)里的圖片并返回

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é)

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

相關(guān)文章

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

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

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

    Android中的ViewPager視圖滑動(dòng)切換類的入門實(shí)例教程

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

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

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

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

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

    Android測(cè)試方法總結(jié)

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

    Android基于Service的音樂播放器

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

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

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

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

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

    Android滾輪選擇時(shí)間控件使用詳解

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

    Android 在程序運(yùn)行時(shí)申請(qǐng)權(quán)限的實(shí)例講解

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

最新評(píng)論

平顶山市| 包头市| 永丰县| 玉田县| 丹江口市| 饶平县| 龙江县| 齐齐哈尔市| 阿拉善右旗| 兴宁市| 西贡区| 扎赉特旗| 柳河县| 内丘县| 工布江达县| 侯马市| 高尔夫| 巴中市| 广水市| 新巴尔虎右旗| 安泽县| 临夏县| 武威市| 鹿邑县| 上饶县| 清水河县| 林西县| 灵川县| 太仆寺旗| 应用必备| 安仁县| 梅州市| 平泉县| 肃宁县| 汕尾市| 石林| 荃湾区| 姜堰市| 礼泉县| 沁源县| 镇坪县|