내 Android 애플리케이션에서 사용자가 갤러리를 열고 이미지를 선택하기위한 버튼을 클릭 할 수있게해야합니다. 그런 다음 레이아웃 (UI)의 특정 이미지를 이미지 뷰에로드해야합니다. 그리고 몇 가지 코드가 있지만 그것은 java.lang.outofmemory.Please 사람이 나를 도울 수 온다? 여기Android : 이미지를 업로드하는 동안 기기에서 앱이 다운 됨, java.lang.outofMemoryError
1
A
답변
3
당신은 onActivityResult를() 메소드의 이미지 URI를 디코딩한다. 이 메소드를 호출하여 decodeBitmap을 디코딩하십시오. 주제 이 효율적으로
http://developer.android.com/training/displaying-bitmaps/index.html
희망이 도움말을 비트 맵을 표시하지만 자세한 내용은
/**
* This is very useful to overcome Memory waring issue while selecting image
* from Gallery
*
* @param selectedImage
* @param context
* @return Bitmap
* @throws FileNotFoundException
*/
public static Bitmap decodeBitmap(Uri selectedImage, Context context)
throws FileNotFoundException {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(context.getContentResolver()
.openInputStream(selectedImage), null, o);
final int REQUIRED_SIZE = 100;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp/2 < REQUIRED_SIZE || height_tmp/2 < REQUIRED_SIZE) {
break;
}
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(context.getContentResolver()
.openInputStream(selectedImage), null, o2);
}
는 간다.
+0
고맙습니다. 벌금.. – shakthivel
0
이 예외가 제대로 비트 맵을 표시하는 방법을 이유를 확인할 수있는 것들 : http://developer.android.com/training/displaying-bitmaps/index.html
관련 문제
- 1. ldpi 화면이있는 기기에서 앱이 다운 됨
- 2. 보기가 변경되는 동안 Android 앱이 다운 됨
- 3. 시작하는 동안 Android 앱이 다운 됨
- 4. FragmentActivity로 확장하는 동안 Android 앱이 다운 됨
- 5. Android - 앱이 다운 됨
- 6. Android 앱이 항상 다운 됨
- 7. 로딩시 Android 앱이 다운 됨
- 8. 시작시 Android 앱이 다운 됨
- 9. Android Tesseract 앱이 다운 됨
- 10. 시작시 Android 앱이 다운 됨
- 11. FragmentTransaction.replace에서 Android 앱이 다운 됨
- 12. 출시 모드에서 Android 앱이 다운 됨
- 13. 타이머 루프 중에 Android 앱이 다운 됨
- 14. 이미지를 다운로드하는 중 iPhone4s에서 앱이 다운 됨
- 15. Android 4.4.4에서 Android 앱이 다운 됨
- 16. 특정 기기에서 iphone이 다운 됨
- 17. 이미지 수가 많아 Android 앱이 다운 됨
- 18. 측면 탐색을 구현하는 동안 앱이 다운 됨
- 19. Android 6.0.1을 설치 한 후 디버깅하는 동안 앱이 다운 됨
- 20. Android : 버튼 클릭시 앱이 다운 됨
- 21. 목록 스크롤 후 Android 앱이 다운 됨
- 22. 로드시 Android 앱이 다운 됨 - classNotFoundException
- 23. getElementsByTagName에서 앱이 다운 됨
- 24. 이미지 전송 중 앱이 다운 됨 Android
- 25. OS 레이어에서 Android 앱이 다운 됨
- 26. Android 앱이 다운 됨 : 메모리가 부족합니다.
- 27. Android : 새로운 활동 시작시 앱이 다운 됨
- 28. 간단한 OpenGL 코드에서 Android 앱이 다운 됨
- 29. 스레드를 사용할 때 Android 앱이 다운 됨
- 30. 치명적인 예외가있는 시작시 Android 앱이 다운 됨
로드하는 비트 맵이 테스트 장치에서 사용 가능한 메모리 양에 비해 너무 클 수 있습니다. 또는 한 번에 너무 많은 비트 맵을 갤러리에로드 할 수 있습니다. 사람들은 종종 이것을 실행하기 때문에 Android에서 비트 맵을 처리 할 때는 코드에 미리 고려해야합니다. 다음은 Romain Guy가이 주제를 다루는 프레젠테이션입니다. https://dl.google.com/io/2009/pres/Th_0230_TurboChargeYourUI-HowtomakeyourAndroidUIfastandefficient.pdf – Turnsole
@Turnsole 작동에 많은 감사를드립니다. – shakthivel