드로어 블 폴더에 많은 리소스가 있습니다 .5 백 킬로바이트 이상의 큰 크기가 있습니다. 한 번에 srollView에서 25 개의 이미지를 모두로드해야합니다. 평소처럼 나는 추억이 다 떨어졌습니다. 프로그래밍 방식으로 이미지의 크기를 줄일 수있는 방법이 있습니까?드로어 블에서 파일 만들기
이 함수가 있는데 매개 변수가 File이고 drawable에서 File을 만드는 방법을 모르겠습니다.
private Bitmap decodeFile(File f){ Bitmap b = null; try { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream fis = new FileInputStream(f); BitmapFactory.decodeStream(fis, null, o); fis.close(); int scale = 1; if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) { scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE/(double) Math.max(o.outHeight, o.outWidth))/Math.log(0.5))); } //Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; fis = new FileInputStream(f); b = BitmapFactory.decodeStream(fis, null, o2); fis.close(); } catch (FileNotFoundException e) { } return b; }
나는 탐색 시스템이 메모리 부족을 보여주는하고 스택에서 다시 다른 뷰를 제거하고 다수의 후이 화면을 주기적으로 여러 번 thorugh 가야하지만 실제로 필요합니다. 도와주세요.
도움 주셔서 감사합니다. 이 오류가 발생합니다 ... InputStream is = (InputStream) getResources(). openRawResource (R.drawable.image); . 제발 파일을 만드는 방법도 말해. – James
나는 이것을 이렇게 던져야했다. InputStream = (InputStream) getResources(). openRawResource (R.drawable.simplelist); – James
"getResources"는 Activity 클래스에서 정의 된 함수이므로 입력 스트림을 가져 오는 코드를 작성한 곳의 활동 컨텍스트가 있는지 확인하십시오. – mudit