您好,登錄后才能下訂單哦!
public void reasonAdd(View v) { final String [] strs=new String[]{"拍照","相冊"}; AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setTitle("照片"); builder.setItems(strs, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //拍照可以用兩種方法來實(shí)現(xiàn) //1.調(diào)用系統(tǒng)相機(jī) 2.自定義相機(jī) if (which==0) { Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,1); } //調(diào)用系統(tǒng)相冊 if (which==1) { Intent intent=new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("p_w_picpath/*"); 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); } } }); builder.show(); } // 寫一個方法來實(shí)現(xiàn)相機(jī) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode== Activity.RESULT_OK) { String sdStatus= Environment.getExternalStorageState(); if(!sdStatus.equals(Environment.MEDIA_MOUNTED)) { Log.i("TestFile", "SD card is not avaiable right now"); return; } String name= Calendar.getInstance(Locale.CANADA)+".jpg"; Bundle bundle=data.getExtras(); FileOutputStream b=null; // 實(shí)現(xiàn)設(shè)置圖片的大小,然后顯示 Intent intent1=new Intent("com.android.camera.actioin.CROP"); intent1.putExtra("crop","true"); intent1.putExtra("outputX",250); intent1.putExtra("outputY", 250); intent1.putExtra("aspectX",1); intent1.putExtra("aspectY", 1); Bitmap source= (Bitmap) bundle.get("data"); file=new File("/sdcard/myp_w_picpath/"); file.mkdir(); String Filename="/sdcard/myp_w_picpath/"+name; try { b=new FileOutputStream(Filename); source.compress(Bitmap.CompressFormat.JPEG,100,b); b.flush(); b.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } leave_iv_icon.setImageBitmap(source); icon=source; }else if(resultCode==0) { Bitmap cameraBitmap = (Bitmap) data.getExtras().get("data"); leave_iv_icon.setImageBitmap(cameraBitmap); icon=cameraBitmap; } }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。