안드로이드 자바 쌩초보구요.
어찌어찌 앱을 하나 완성해서 잘 돌아가고있는상태입니다.
이번에 파일 업로드 기능 업데이트 때문에 또 여기저기 돌아다니면서 삽질을 좀 하고 있네요.
질문 내용은 제목그대로 outofmemory 관련입니다.
이렇게 사진을 앨범과 내장 카메라를 이용한 사진찍기 두가지 방법으로 만들었구요.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
No++;
try {
if (requestCode == REQ_IMAGE_SELECT) {
Uri selPhoneUri = data.getData();
String[] proj = { MediaColumns.DATA };
Cursor cursor = getContentResolver().query(selPhoneUri, proj, null, null, null);
int index = cursor.getColumnIndex(MediaColumns.DATA);
cursor.moveToFirst();
String fullPath = cursor.getString(index);
int tempWidth = getBitmapOfWidth(fullPath.toString());
int tempHeight = getBitmapOfHeight(fullPath.toString());
if(tempWidth>600) tempWidth = 600;
if(tempHeight>800) tempHeight = 800;
Uri bitmapUri = Uri.fromFile(new File(fullPath));
Matrix matrix = new Matrix();
matrix.postRotate(90);
if(tempWidth>tempHeight){
Bitmap retateBitmap = Bitmap.createBitmap(BitmapFactory.decodeFile(bitmapUri.getPath()), 0, 0, tempWidth, tempHeight, matrix, true);
retateBitmap = Bitmap.createScaledBitmap(retateBitmap, 600, 800, true);
//Bitmap retateBitmap = Bitmap.
String fileName = System.currentTimeMillis()+".jpg";
saveImage(retateBitmap, fileName);
cursor.close();
DoFileUpload(urlString, "sdcard/DCIM/"+fileName);
String fileArray[] = fullPath.split("/", 0);
Log.i("fileName", fileName);
webView.loadUrl("javascript:loadImg1('"+fileName+"','"+No+"')");
}else{
Bitmap retateBitmap = BitmapFactory.decodeFile(bitmapUri.getPath());
String fileName = System.currentTimeMillis()+".jpg";
saveImage(retateBitmap, fileName);
cursor.close();
DoFileUpload(urlString, "sdcard/DCIM/"+fileName);
String fileArray[] = fullPath.split("/", 0);
Log.i("fileName", fileName);
webView.loadUrl("javascript:loadImg1('"+fileName+"','"+No+"')");
}
} else if (requestCode == CODE_IMAGE_CAPTURE) {
if (resultCode == RESULT_CANCELED) { return; }
Uri uriImages = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] IMAGE_PROJECTION = { MediaColumns.DATA, BaseColumns._ID, };
try {
Cursor cursorImages = getContentResolver().query(uriImages, IMAGE_PROJECTION, null, null, null);
if (cursorImages != null && cursorImages.moveToLast()) {
fromFile = new File(cursorImages.getString(0));
int tempWidth = getBitmapOfWidth(fromFile.toString());
int tempHeight = getBitmapOfHeight(fromFile.toString());
String fullPath = fromFile.toString();
Uri bitmapUri = Uri.fromFile(new File(fullPath));
Matrix matrix = new Matrix();
matrix.postRotate(90);
if(tempWidth>tempHeight) {
Bitmap retateBitmap;
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 1;
option.inPurgeable = true;
option.inDither = true;
retateBitmap = Bitmap.createBitmap(BitmapFactory.decodeFile(bitmapUri.getPath()), 0, 0, tempWidth, tempHeight, matrix, true);
retateBitmap = Bitmap.createScaledBitmap(retateBitmap, 600, 800, true);
String fileName = System.currentTimeMillis()+".jpg";
saveImage(retateBitmap, fileName);
DoFileUpload(urlString, "sdcard/DCIM/"+fileName);
String fileArray[] = fullPath.split("/", 0);
webView.loadUrl("javascript:loadImg1('"+fileName+"','"+No+"')");
}else {
Bitmap retateBitmap;
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 1;
option.inPurgeable = true;
option.inDither = true;
retateBitmap = BitmapFactory.decodeFile(bitmapUri.getPath());
String fileName = System.currentTimeMillis()+".jpg";
saveImage(retateBitmap, fileName);
DoFileUpload(urlString, "sdcard/DCIM/"+fileName);
String fileArray[] = fullPath.split("/", 0);
webView.loadUrl("javascript:loadImg1('"+fileName+"','"+No+"')");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
사실 코드 이해도 좀 버겁네요.
암튼 위와 같이 코딩된 상태구요.
앨범에서 선택해서 올리는기능은 어쨌든 이상없이 잘 올라가고 보여지고 합니다.
문제는 카메라로 사진을 찍어서 업로드 하면 outofmemory 에러가 나네요.
어느 부분을 어떻게 손봐야할지 감조차 잡히지 않네요.
도움좀 부탁드리겠습니다.