1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      android如何從系統(tǒng)或相機中獲取照片

      public class MainActivity extends Activity

      成都創(chuàng)新互聯(lián)專注于章貢網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供章貢營銷型網(wǎng)站建設(shè),章貢網(wǎng)站制作、章貢網(wǎng)頁設(shè)計、章貢網(wǎng)站官網(wǎng)定制、小程序設(shè)計服務(wù),打造章貢網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供章貢網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

      {

      private static final int PHOTO_REQUEST_CAREMA = 1;// 拍照

      private static final int PHOTO_REQUEST_GALLERY = 2;// 從相冊中選擇

      private static final int PHOTO_REQUEST_CUT = 3;// 結(jié)果

      private ImageView iv_p_w_picpath;

      /* 頭像名稱 */

      private static final String PHOTO_FILE_NAME = "temp_photo.jpg";

      private File tempFile;

      @Override

      protected void onCreate(Bundle savedInstanceState)

      {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);

      this.iv_p_w_picpath = (ImageView) this.findViewById(R.id.iv_p_w_picpath);

      }

      /*

      * 從相冊獲取

      */

      public void gallery(View view)

      {

      // 激活系統(tǒng)圖庫,選擇一張圖片

      Intent intent = new Intent(Intent.ACTION_PICK);

      intent.setType("p_w_picpath/*");

      // 開啟一個帶有返回值的Activity,請求碼為PHOTO_REQUEST_GALLERY

      startActivityForResult(intent, PHOTO_REQUEST_GALLERY);

      }

      /*

      * 從相機獲取

      */

      public void camera(View view)

      {

      // 激活相機

      Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

      // 判斷存儲卡是否可以用,可用進行存儲

      if (hasSdcard())

      {

      tempFile = new File(Environment.getExternalStorageDirectory(),

      PHOTO_FILE_NAME);

      // 從文件中創(chuàng)建uri

      Uri uri = Uri.fromFile(tempFile);

      intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

      }

      // 開啟一個帶有返回值的Activity,請求碼為PHOTO_REQUEST_CAREMA

      startActivityForResult(intent, PHOTO_REQUEST_CAREMA);

      }

      /*

      * 剪切圖片

      */

      private void crop(Uri uri)

      {

      // 裁剪圖片意圖

      Intent intent = new Intent("com.android.camera.action.CROP");

      intent.setDataAndType(uri, "p_w_picpath/*");

      intent.putExtra("crop", "true");

      // 裁剪框的比例,1:1

      intent.putExtra("aspectX", 1);

      intent.putExtra("aspectY", 1);

      // 裁剪后輸出圖片的尺寸大小

      intent.putExtra("outputX", 250);

      intent.putExtra("outputY", 250);

      intent.putExtra("outputFormat", "JPEG");// 圖片格式

      intent.putExtra("noFaceDetection", true);// 取消人臉識別

      intent.putExtra("return-data", true);

      // 開啟一個帶有返回值的Activity,請求碼為PHOTO_REQUEST_CUT

      startActivityForResult(intent, PHOTO_REQUEST_CUT);

      }

      /*

      * 判斷sdcard是否被掛載

      */

      private boolean hasSdcard()

      {

      if (Environment.getExternalStorageState().equals(

      Environment.MEDIA_MOUNTED))

      {

      return true;

      } else

      {

      return false;

      }

      }

      @Override

      protected void onActivityResult(int requestCode, int resultCode, Intent data)

      {

      if (requestCode == PHOTO_REQUEST_GALLERY)

      {

      // 從相冊返回的數(shù)據(jù)

      if (data != null)

      {

      // 得到圖片的全路徑

      Uri uri = data.getData();

      crop(uri);

      }

      } else if (requestCode == PHOTO_REQUEST_CAREMA)

      {

      // 從相機返回的數(shù)據(jù)

      if (hasSdcard())

      {

      crop(Uri.fromFile(tempFile));

      } else

      {

      Toast.makeText(MainActivity.this, "未找到存儲卡,無法存儲照片!", 0).show();

      }

      } else if (requestCode == PHOTO_REQUEST_CUT)

      {

      // 從剪切圖片返回的數(shù)據(jù)

      if (data != null)

      {

      Bitmap bitmap = data.getParcelableExtra("data");

      this.iv_p_w_picpath.setImageBitmap(bitmap);

      }

      try

      {

      // 將臨時文件刪除

      tempFile.delete();

      } catch (Exception e)

      {

      e.printStackTrace();

      }

      }

      super.onActivityResult(requestCode, resultCode, data);

      }

      }


      網(wǎng)站題目:android如何從系統(tǒng)或相機中獲取照片
      轉(zhuǎn)載注明:http://www.ef60e0e.cn/article/jhgsjg.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        米泉市| 玉林市| 遂川县| 临高县| 邢台县| 泊头市| 自贡市| 翁源县| 广平县| 新绛县| 宁安市| 无锡市| 安阳市| 金阳县| 拉萨市| 招远市| 科技| 水富县| 普兰店市| 新泰市| 昆明市| 灵石县| 巍山| 离岛区| 县级市| 平顺县| 梨树县| 岳阳县| 鱼台县| 怀化市| 晴隆县| 额济纳旗| 乌鲁木齐市| 天门市| 息烽县| 金平| 钟山县| 云梦县| 日土县| 恭城| 佛教|