2013-10-09 5 views
0

(기본값) 카메라 앱에서 반환 한 이미지를 자르고 있지만 그 결과 크기가 더 큰 파일 (~ 4x 큰 이미지)입니다.이미지 자르기에서 예기치 않은 동작이 발생했습니다.

Bitmap bitmapOrg = BitmapFactory.decodeFile(OrigImagePath); 

int width = bitmapOrg.getWidth(); 
int height = bitmapOrg.getHeight(); 
int shortLength = (width <= height) ? width : height; 

// square proportions 
int xOffset = (width - shortLength)/2; 
int yOffset = (height - shortLength)/2; 

Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, xOffset, yOffset, shortLength, shortLength); 

// save 
File f = new File(Util.getDir(OrigImagePath) + File.separator + "thumbnail.jpg"); 

try { 
    FileOutputStream out = new FileOutputStream(f); 
    resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 
    out.flush(); 
    out.close(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

방금 ​​파일 크기 차이에 대해 알았습니다. 당연히 나는 OutOfMemoryErrors을 얻고 있었다. 나는 BitmapFactory.Options inSampleSize을 사용할 수 있지만 실제로는 원본 이미지를 잘라내지 않고 자르고 싶습니다. 분명히 내가 여기에서 빠진 것이있다.

+0

'resizedBitmap.compress (Bitmap.CompressFormat.JPEG, 100, out);'비트 맵의 ​​압축되지 않은 jpeg 버전을 생성합니다. – njzk2

+0

원래 비트 맵이 이미 압축되어 있습니까? 나는 그 결과가 원본과 같기를 바랄 뿐이다. – user1923613

+0

비트 맵은 정의에 따라 압축되지 않습니다. 그러나 'OrigImagePath'는 압축 된 이미지 파일입니다. 비트 맵으로 디코딩하면 결과 비트 맵이 압축되지 않습니다. 'f '로 압축하면, 선택하는 형식은 무손실이기 때문에 매우 큽니다. – njzk2

답변

0

아마 당신은이를 시도해야한다 : 대신의

Bitmap resizedBitmap = Bitmap.createBitmap (xOffset, yOffset, Bitmap.Config.RGB_565); 

을 :

Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, xOffset, yOffset, shortLength, shortLength); 

희망이 도움이!

관련 문제