SC20120410-155911  

.java

extends Activity

//打開手機的媒體瀏覽器

private opImageLibrary(){

   Intent intent = new Intent();
   /* 開啟Pictures畫面Type設定為image */
   intent.setType("image/*");
   /* 使用Intent.ACTION_GET_CONTENT這個Action */
   intent.setAction(Intent.ACTION_GET_CONTENT);
   /* 取得相片後返回本畫面 */
   startActivityForResult(intent, 1);

}

//取得照片後返回主畫面
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

   if (resultCode == RESULT_OK) {
      Uri uri = data.getData();
      ContentResolver cr = this.getContentResolver();
      try {
         Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
         ImageView imageView = (ImageView) findViewById(R.id.more_set_account_edit_image);
         /* 將Bitmap設定到ImageView */
         imageView.setImageBitmap(bitmap);

         //計算手機解析度並調整image大小(自己另外寫的class)
         layoutcontent.setImageViewParam(imageView);
         // layoutcontent.setImageViewParam(imageView, cr.openInputStream(uri).toString());
      } catch (FileNotFoundException e) {
         Log.e("Exception", e.getMessage(),e);
      }

   }
   super.onActivityResult(requestCode, resultCode, data);
}

 

參考來源:http://fecbob.pixnet.net/blog/post/36933359

arrow
arrow
    文章標籤
    andorid
    全站熱搜
    創作者介紹
    創作者 鴨鴨仔 的頭像
    鴨鴨仔

    DUCK,Fearless!

    鴨鴨仔 發表在 痞客邦 留言(0) 人氣()