2010-11-23 5 views
0

휴대 전화에 이미지를 올려서 1MB 이상의 서버로 보내고 싶다면 그 이미지를 가져 와서 어쨌든 원본 이미지를 어지럽히 지 않고 작은 크기로 축소하고 싶습니다. 나는 전화로부터 어떻게 정보를 얻는 지 알았고 서버로 보내는 방법도 알고있다. 1MB보다 큰 대용량 파일로 인해 문제가 발생하기 때문에 이미지를 더 작게 만드는 방법을 알아야한다.Android 큰 이미지 크기 축소

답변

1

당신과 같이 비트 맵을 확장 할 수 있습니다 :

// Load in your bitmap here, I'll leave this detail up to you 
Bitmap _bitmapPreScale = BitmapFactory.decodeResource(resources, fieldValue); 

int oldWidth = _bitmapPreScale.getWidth(); 
int oldHeight = _bitmapPreScale.getHeight(); 
int newWidth = width; // whatever your desired width and height are 
int newHeight = height; 

// calculate the scale 
float scaleWidth = ((float) newWidth)/oldWidth; 
float scaleHeight = ((float) newHeight)/oldHeight; 

// create a matrix for the manipulation 
Matrix matrix = new Matrix(); 
// resize the bit map 
matrix.postScale(scaleWidth, scaleHeight); 

// recreate the new Bitmap 
Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true); 
+0

선택한 이미지의 파일 크기를 확인할 수있는 방법이 있습니까? 파일 크기가 1MB 이상이거나 1024kb 이상인 경우 위와 같이 게시 한 것처럼 작은 파일 크기의 이미지 만 해당 HD 이미지에 문제가 없습니다. 감사합니다 – user516883

+0

좋아, 내가이 파일을 사용할 수 있다고 생각 = new File ("infilename"); 그럼 그 속임수를 할 것이라고 생각 file.length 전화 – user516883

관련 문제