2012-12-26 3 views
1

사진을 찍어 편집해야합니다. 원본 카메라를 사용하여 큰 크기의 이미지를 반환하므로 편집 할 새 템플릿 이미지를 만들 때 outOfMemoryError 때문에 응용 프로그램이 닫힙니다. 내 응용 프로그램에 이미지를로드하기 전에 이미지의 크기를 조절할 수있는 방법이 있습니까? 카메라카메라로 사진 찍고 편집하십시오

내 코드 걸릴 이미지 :

void loadImageFromCamera(){ 
    Intent takePicture = new Intent("android.media.action.IMAGE_CAPTURE"); 
    File photo = null; 
    try{ 
     // place where to store camera taken picture 
     photo = this.createTemporaryFile("picture", ".jpg"); 
     photo.delete(); 
    } catch(Exception e){ 

    } 
    mImageUri = Uri.fromFile(photo); 
    takePicture.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); 
    startActivityForResult(takePicture, 0); 
} 
private File createTemporaryFile(String part, String ext) throws Exception{ 
    File tempDir = Environment.getExternalStorageDirectory(); 
    tempDir = new File(tempDir.getAbsolutePath() + "/.temp/"); 
    if(!tempDir.exists()){ 
     tempDir.mkdir(); 
    } 
    return File.createTempFile(part, ext, tempDir); 
} 
public void grabImage(){ 
    this.getContentResolver().notifyChange(mImageUri, null); 
    ContentResolver cr = this.getContentResolver(); 
    try { 
     originImage = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri); 
    }catch (Exception e){ 

    } 

} 

답변

1

예는

public static Bitmap getResizedBitmap(Bitmap image, int newHeight, int newWidth) { 
    int width = image.getWidth(); 
    int height = image.getHeight(); 
    float scaleWidth = ((float) newWidth)/width; 
    float scaleHeight = ((float) newHeight)/height; 
    // create a matrix for the manipulation 
    Matrix matrix = new Matrix(); 
    // resize the bit map 
    matrix.postScale(scaleWidth, scaleHeight); 
    // recreate the new Bitmap 
    Bitmap resizedBitmap = Bitmap.createBitmap(image, 0, 0, width, height, 
      matrix, false); 
    return resizedBitmap; 
} 
가로드 할 때 이미지 크기를 조정할 수 없습니다
+0

때문에 이미지를 크기를 조정하려면 이미지 사용에게 다음과 같은 방법으로 크기를 조정할 수 있습니다 outOfMemoryError. \ n 코드를 추가하려고하지만 작동하지 않습니다 : |. 내 응용 프로그램에로드되기 전에 크기가 조정되어야합니다. – Sunary

+0

예 응용 프로그램로드 후 이미지의 크기가 조정됩니다. –

+0

고마워요.하지만로드하기 전에 크기를 조정해야합니다. 그것을로드하기 전에 어쨌든 이미지 크기를 조정할 수 있습니까? – Sunary

관련 문제