2014-11-04 1 views
0

에서 보여 이 같은 :내가 이런 안드로이드 카메라로 사진을 촬영하고자하는 이미지 뷰

<ImageView 
     android:id="@+id/nfcresult_imageview_photo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" 
     android:adjustViewBounds="true" 
     android:clickable="true" 
     android:contentDescription="@string/imageview_photo_description" /> 

그것은 모든 작동하지만 이미지 뷰에 표시된 사진은보다 훨씬 작다 0 사진의 카메라로 찍은 사진. 내가 원하는 것은 내 ImageView에서 작은 미리보기를 가지고 ImageView에 OnClickListener를 추가하여 원본 크기와 해상도로 원본 사진을 보여주는 대화 상자를 여는 것입니다. 그것은 캔트 그것을하는 것이 어렵다. 그러나 나는 실제로 어떻게 기울어 져야하는지에 관해 안다.

대화 상자를 만들려면 내가이 할 사진을 보여 :

ImageView clone = new ImageView(this); 
clone.setImageBitmap(((BitmapDrawable)this.imageViewPhoto.getDrawable()).getBitmap()); 

DialogManager.showImageDialog(this, this.getResources().getString(R.string.title_photo), clone); 

showImageDialog :

public static void showImageDialog(Context context, String title, ImageView imageView) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(context); 

    builder.setTitle(title); 
    builder.setCancelable(false); 
    builder.setView(imageView); 
    builder.setPositiveButton(context.getResources().getString(R.string.button_back), new DialogInterface.OnClickListener() { 
     /** 
     * 
     */ 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      dialog.dismiss(); 
     } 
    }); 

    builder.create().show(); 
} 

이 대화는 이제 이미지 뷰에 저장된 사진의 크기의 사진을 보여줍니다 하지만 원본 크기와 원본 해상도가 원래 사진 인 으로 표시하고 싶지만 이미 말했듯이 ImageView의 원본 크기가 더 작아야합니다 ( 사진).

어떻게 할 수 있습니까?

+0

http://androidexample.com/Camera_Photo_Capture_And_Show_Captured_Photo_On_Activity_/index.php?view=article_discription&aid=77&aaid=101 –

+0

http://stackoverflow.com/questions/5991319/capture-image -from-camera-and-display-in-activity –

+0

링크를 가져 주셔서 감사합니다 ... 그러나 많이 사용되지 않는 것들이 있습니다 ... – Mulgard

답변

0

솔루션 :

/** 
* 
*/ 
private void performAddPhoto() { 
    String timeStamp = Clock.getTimeStamp(); 
    String fileName = "Food_Shot_" + timeStamp + ".jpg"; 

    this.imagePath = Environment.getExternalStorageDirectory() + "/images/" + fileName; 

    File file = new File(this.imagePath); 
    file.getParentFile().mkdirs(); 

    try { 
     file.createNewFile(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); 
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); 

    startActivityForResult(intent, Globals.REQUEST_CODE_CAMERA); 
} 

/** 
* 
*/ 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if(requestCode == Globals.REQUEST_CODE_CAMERA) { 
     if(resultCode == RESULT_OK) { 
      this.onPhotoTaken(); 
     } 
    } 
} 

/** 
* 
*/ 
private void onPhotoTaken() { 
    this.imageTaken = true; 

    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inSampleSize = 4; 

    Bitmap bitmap = BitmapFactory.decodeFile(this.imagePath, options); 
    this.imageViewPhoto.setImageBitmap(bitmap); 
} 

/** 
* 
*/ 
private void performShowPhoto() { 
    ImageView imageView = new ImageView(this); 
    Bitmap bitmap = BitmapFactory.decodeFile(this.imagePath); 

    imageView.setImageBitmap(bitmap); 

    DialogManager.showImageDialog(this, this.getResources().getString(R.string.title_photo), imageView); 
} 
0

대신 안드로이드 : layout_width = "wrap_content"(우측 값을 선택하는 대신에 (100, 200)의) 높이와 폭의 종횡비를 유지

를 특정 DP 값

<ImageView 
     android:id="@+id/nfcresult_imageview_photo" 
     android:layout_width="100dp" 
     android:layout_height="200dp" 
     android:src="@drawable/ic_launcher" 
     android:adjustViewBounds="true" 
     android:clickable="true" 
     android:contentDescription="@string/imageview_photo_description" /> 

에 이미지 뷰의 폭과 높이를 설정할

+0

wrap_content content도 잘못되었습니다. –

0

"MediaStore.EXTRA_OUTPUT"이라는 의도로 여분을 넣어야합니다. 여기서 저장할 그림의 URI를 설정해야합니다. 콜백 함수가 호출 된 후 선택한 URI에서 그림을로드 할 수 있습니다. 전체 해상도로 사진을 얻을 수 있습니다.

관련 문제