2014-11-29 1 views
1

사진을 내부 저장소로 가져 와서 저장하는 수업을 만들었지 만 문제는 전체 크기 사진이 아닌 미리보기 이미지를 저장하는 것입니다. 내가 레이아웃에 넣어 비트 맵 미리보기를 반환내부 저장소에 저장된 Android 그림이 미리보기 이미지입니다.

pm = new PhotoManager(getActivity(), Q_ID, getArguments().getString("type"), fm, new PhotoCallbackListener() { 
     @Override 
     public void callback(Bitmap mImageBitmap, String file) { 

      imagePreview.setImageBitmap(mImageBitmap); 
      filePath = file; 

     } 

    }); 

Button buttonPhoto = (Button) view.findViewById(R.id.q4BtnPhoto); 
    buttonPhoto.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      pm.init(); 
     } 

    }); 

, 그냥 테스트 파일 경로 :

public class PhotoManager { 

private final static String DEBUG_TAG = "PHOTOMANAGER"; 
private String mCurrentPhotoPath = ""; 
private String filePath = ""; 
private Intent takePictureIntent; 
private Activity activity; 
private String type; 
private int Q_ID; 
private PhotoCallbackListener mListener; 
private FragmentManager fragManager; 

public void setListener(PhotoCallbackListener listener) { 
    mListener = listener; 
} 

public PhotoManager(Activity activity, int Q_ID, String type, FragmentManager fm, PhotoCallbackListener listener) { 
    this.activity = activity; 
    this.Q_ID = Q_ID; 
    this.type = type; 
    this.mListener = listener; 
    this.fragManager = fm; 
} 
// init la vue de la camera 
public void init(){ 
    dispatchTakePictureIntent(11); 
} 
// affiche la camera 
private void dispatchTakePictureIntent(final int actionCode) { 


    Fragment f = new Fragment() { 
     @Override 
     public void onAttach(Activity activity) { 
      super.onAttach(activity); 
      takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

      startActivityForResult(takePictureIntent, actionCode); 
     } 

     @Override 
     public void onActivityResult(int requestCode, int resultCode, 
            Intent data) { 
      if (data != null) { 
       try { 
        handleSmallCameraPhoto(data); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       // efface la photo créee de la galerie 
       activity.getContentResolver().delete(data.getData(), null, null); 
      } 

     } 
    }; 
    FragmentTransaction fragmentTransaction = this.fragManager 
      .beginTransaction(); 
    fragmentTransaction.add(f, "getpicture"); 
    fragmentTransaction.commit(); 


} 

private void handleSmallCameraPhoto(Intent intent) throws IOException { 
    Bundle extras = intent.getExtras(); 
    Bitmap mImageBitmap = (Bitmap) extras.get("data"); 

    File f = createImageFile(); 
    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); 

    filePath = saveToInternalStorage(mImageBitmap); 

    galleryAddPic(); 

    mListener.callback(mImageBitmap, filePath); 

} 

private File createImageFile() throws IOException { 
    // Create an image file name 
    Log.d(DEBUG_TAG,"createImageFile"); 
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date(0)); 
    String imageFileName = timeStamp + "_"; 
    File image = File.createTempFile(
      imageFileName, 
      ".jpg", 
      null //default location for temporary files 
    ); 
    mCurrentPhotoPath = image.getAbsolutePath(); 
    Log.d(DEBUG_TAG,"return "+image.getAbsolutePath()); 

    return image; 
} 

private String saveToInternalStorage(Bitmap bitmapImage){ 

    ContextWrapper cw = new ContextWrapper(activity.getApplicationContext()); 

    Log.d(DEBUG_TAG,"saveToInternalStorage"); 

    File directory = cw.getDir("imageDir_"+type, Context.MODE_PRIVATE); 
    String fileName = "q"+Q_ID+".jpg"; 
    // Create imageDir 
    File mypath = new File(directory, fileName); 

    FileOutputStream fos = null; 
    try { 

     fos = new FileOutputStream(mypath); 

     // Use the compress method on the BitMap object to write image to the OutputStream 
     bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos); 
     fos.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    Log.d(DEBUG_TAG,"return "+directory.getAbsolutePath()); 
    return directory.getAbsolutePath(); 
} 



private void galleryAddPic() { 
    File f = new File(mCurrentPhotoPath); 
    Uri contentUri = Uri.fromFile(f); 
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri); 
    activity.sendBroadcast(mediaScanIntent); 
} 
} 

나는이처럼 사용

는 클래스입니다.

전체 크기의 사진이 저장되지 않은 이유를 이해하는 사람이 있습니까?

감사합니다.

답변

2

자신이 해결 :

내가 큰 실수를 내가 전체 크기되지 내부 저장 썸네일을 저장. 내가 가진 전체 크기 저장된 이미지를 얻을 수 있습니다 handleSmallCameraPhoto 방법에

:

Uri fullsizeImage = intent.getData(); 

나는 다음과 같은 이미지의 비트 맵을 얻을 :

Bitmap mBitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), fullsizeImage); 

을 그리고 난 내 saveToInternalStorage 메서드를 호출 한 후.

+0

자신 만의 문제를 해결할 수 있으면 언제나 좋습니다. 그리고 자신의 답변을 게시 해 주셔서 감사합니다. 나중에 다른 사람을 구할 수도 있습니다. – Difster

관련 문제