2014-10-21 5 views
0

어젯밤에 나는 내 앱이 작동한다고 생각했지만 오늘 아침에는 gremlins가 침입하여 이제 내 앱의 기능을 제대로 작동하지 않게되었습니다.사진이 이미지보기에 표시되지 않음 android

기본적으로 버튼을 사용하면 사진을 찍어서 이미지 뷰에 표시 한 다음 이미지를 이메일에 첨부 할 수 있습니다. 사진 찍을 수 있으며 첨부 파일로 계속 표시됩니다. 이미지 뷰의 미리보기는 완전히 비어 있습니다.

아무도 무슨 일이 일어나는 지 볼 수 있습니까? 나는 안드로이드의 이미지 뷰에 표시 할 이미지에 대해 수행 한 어떤

Hoon_Image = (ImageView) findViewById(R.id.CapturedImage); 
     button_take_photo = (Button)findViewById(R.id.btn_take_photo); 
     button_take_photo.setOnClickListener(new View.OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       try { 
        f = createImageFile(); 
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
        cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); 
        startActivityForResult(cameraIntent, CAMERA_REQUEST); 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 



      } 
     }); 
public File getAlbumDir() 
    { 

     File storageDir = new File(
       Environment.getExternalStoragePublicDirectory(
         Environment.DIRECTORY_PICTURES 
       ), 
       "BAC/" 
     ); 
     // Create directories if needed 
     if (!storageDir.exists()) { 
      storageDir.mkdirs(); 
     } 

     return storageDir; 
    } 
    private File createImageFile() throws IOException { 
     // Create an image file name 

     String imageFileName =getAlbumDir().toString() +"/image.jpg"; 
     File image = new File(imageFileName); 
     return image; 
    } 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode == RESULT_OK) { 
      if(requestCode == CAMERA_REQUEST){ 
       Bitmap photo = BitmapFactory.decodeFile(f.getAbsolutePath()); 
       Hoon_Image.setImageBitmap(photo); 
      } 
     } 
     if (resultCode == RESULT_OK) { 
      if (requestCode == SELECT_PICTURE) { 
       Uri selectedImageUri = data.getData(); 

       //OI FILE Manager 
       filemanagerstring = selectedImageUri.getPath(); 

       //MEDIA GALLERY 
       selectedImagePath = getPath(selectedImageUri); 

       //DEBUG PURPOSE - you can delete this if you want 
       if(selectedImagePath!=null) 
        System.out.println(selectedImagePath); 
       else System.out.println("selectedImagePath is null"); 
       if(filemanagerstring!=null) 
        System.out.println(filemanagerstring); 
       else System.out.println("filemanagerstring is null"); 

       //NOW WE HAVE OUR WANTED STRING 
       if(selectedImagePath!=null) 
        System.out.println("selectedImagePath is the right one for you!"); 
       else 
        System.out.println("filemanagerstring is the right one for you!"); 
      } 
      Bitmap photo = BitmapFactory.decodeFile(selectedImagePath); 
      Hoon_Image.setImageBitmap(photo); 
      Photo_Selected = 1; 
     } 
    } 

답변

0

그래서 내가 잘못하고있는 걸 발견했습니다.

코드 섹션

:

그것은 단지 requestCode가 찾고있는 첫번째보다는 (사진을 선택하고 성공적으로 사진을 복용 모두 일어) 확인 결과의보고 있었다
if (resultCode == RESULT_OK) { 
      if(requestCode == CAMERA_REQUEST){ 

. 이에 코드를 정리

일 :

if(requestCode == CAMERA_REQUEST) { 
      if (resultCode == RESULT_OK){ 
       Bitmap photo = BitmapFactory.decodeFile(f.getAbsolutePath()); 
       Hoon_Image.setImageBitmap(photo); 
0

는 필수 폭과 높이로 파일 객체를 디코딩하는 방법 decodeSampledBitmapFromFile (문자열 경로, INT reqWidth, INT reqHeight)를 사용하는 것입니다 . 다음은 샘플 코드입니다.

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == RESULT_OK) { 
     File file = new File(Environment.getExternalStorageDirectory() 
       + File.separator + "image.jpg"); 
     bitmap = decodeSampledBitmapFromFile(file.getAbsolutePath(), 
       600, 450); 
     imageView.setImageBitmap(bitmap); 

    } 
} 

public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, 
     int reqHeight) { 

    // First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    // Query bitmap without allocating memory 
    options.inJustDecodeBounds = true; 
    // decode file from path 
    BitmapFactory.decodeFile(path, options); 
    // Calculate inSampleSize 
    // Raw height and width of image 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    // decode according to configuration or according best match 
    options.inPreferredConfig = Bitmap.Config.RGB_565; 
    int inSampleSize = 1; 
    if (height > reqHeight) { 
     inSampleSize = Math.round((float) height/(float) reqHeight); 
    } 
    int expectedWidth = width/inSampleSize; 
    if (expectedWidth > reqWidth) { 
     // if(Math.round((float)width/(float)reqWidth) > inSampleSize) // 
     // If bigger SampSize.. 
     inSampleSize = Math.round((float) width/(float) reqWidth); 
    } 
    // if value is greater than 1,sub sample the original image 
    options.inSampleSize = inSampleSize; 
    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    return BitmapFactory.decodeFile(path, options); 
} 
+0

이 정확히하지만 내 질문에 대답하지 않습니다. – scb998

+0

그러나 ImageView에 이미 이미지가 표시됩니까? – avinea28

+0

위의 코드는 밤에 작동했지만 오늘 아침에는 작동하지 않습니다. 내가 그것을 피할 수 있다면 내 애플 리케이션을 다시 코딩하고 싶지 않아. – scb998

관련 문제