2013-06-12 4 views
0

비트 맵 이미지를 표시하는 데 문제가 있습니다. 내 응용 프로그램 사용자는 이미지보기를 클릭하면 카메라를 사용하여 사진을 찍거나 파일에서 사진을 가져 오는 경고 대화 상자가 나타납니다. '이미지'라는 이미지보기가 있습니다. 아래Android 비트 맵 이미지가 이미지보기에 표시되지 않습니다.

if(option == 0) // take a picture option 
        { 
         try 
         { 
          Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

          ContentValues values = new ContentValues(); 
          values.put(MediaStore.Images.Media.TITLE, Constants.PIC_FILENAME_PREFIX + System.currentTimeMillis() + Constants.PIC_FILENAME_SUFFIX); 
          mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 

          captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI); 

          captureIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 2 * 1024 * 1024); // limit to 2MB data 

          startActivityForResult(captureIntent, CAMERA_CAPTURE);// start activity 
         } 
         catch (ActivityNotFoundException anfe) 
         { 
          String errorMessage = "It appears your device does not have camera.."; 
          Toast.makeText(UploadPhoto.this, errorMessage, Toast.LENGTH_SHORT).show(); 

         }          
        } 
        else if(option==1) 
        { 
         Intent intent = new Intent(); 
         intent.setType("image/*"); 
         intent.setAction(Intent.ACTION_GET_CONTENT); 
         startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_FROM_FILE); 
        } 

그리고 내 활동의 결과입니다 :

public void ActivityResult(int request, int result, Intent intentdata) 
    { 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inPurgeable = true; 
     options.inInputShareable = true; 

     if(result ==RESULT_OK) 
     { 
      if(request==SELECT_FROM_FILE) 
      { 
       mCapturedImageURI = intentdata.getData(); 
      } 

      String[] projection = { MediaStore.Images.Media.DATA }; 
      Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
      if(null==cursor) 
      { 
       return; 
      } 

      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 

      cursor.moveToFirst(); 
      mCapturedFilePath = cursor.getString(column_index); 
      stopManagingCursor(cursor); 
      cursor.close(); 

      // compute the boundary first 
      options.inJustDecodeBounds = true; 
      Bitmap bitmap = BitmapFactory.decodeFile(mCapturedFilePath, options); 
      // get image from file 
      options.inSampleSize = ImageUtil.calculateInSampleSize(options, Constants.PIC_IMAGE_DISP_WIDTH, Constants.PIC_IMAGE_DISP_HEIGHT); 
      options.inJustDecodeBounds = false; 
      bitmap = BitmapFactory.decodeFile(mCapturedFilePath, options); 

      bitmap = Bitmap.createScaledBitmap(bitmap, Constants.PIC_IMAGE_DISP_WIDTH, Constants.PIC_IMAGE_DISP_HEIGHT, false); 

      image.setImageBitmap(bitmap);//I'm trying to change this imageview 
     } 
    } 

사용자가 옵션 중 하나를 클릭하고 걸리거나 파일을 선택의 이미지 뷰가 변경되지 않습니다 여기 내 경고 대화 청취자입니다. 누구에게 추천이 있습니까?

+0

에서

있습니까? – Zorayr

답변

1

방법은

보호 무효 onActivityResult를 (INT의 requestCode가, INT의의 resultCode, 의도 의도)

당신이 여기 typoed 경우, 이미지를 설정 한 후 무효화()를 추가하는 시도해야합니다.

+0

나는 무엇을했는지 모르지만 지금은 효과가있는 것 같습니다. 덕분에 무작위 시민 –

+0

나는 동일한 문제가 있고 나는 당신의 해결책을 시도했다 그러나 어떤 운도. 같은 다른 솔루션? – Hiren

0

나는 나를 위해 또 다른 해결책과 그 일을 발견했다. 모든 로그 캣 출력은 here

final ImageView thumb = (ImageView) findViewById(R.id.thumbnail); 
    thumb.post(new Runnable() { 
     @Override 
     public void run() 
     { 
      Bitmap bmp = BitmapFactory.decodeFile(image_path); 
      thumb.setImageBitmap(bmp); 
      Toast.makeText(this, "Image Saved", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
관련 문제