버튼을 눌러 설정할 수있는 여러 개의 배경 화면을 보여주는 응용 프로그램을 만들려고합니다. Threrfore 10 개의 다른 조각으로 ViewPager를 만들었습니다. 각 조각은 전체 화면으로 배경 화면의 섹션을 표시해야합니다. 문제는 월페이퍼가 OutOfMemoryException을 초래하는 고화질 (3000 * 2500)이라는 것입니다. 이것이 내가이 고해상도가 아닌 화면 크기의 비트 맵으로 가득 찬 ArrayList를 처음 생성하려고했던 이유입니다. 그래도 OutOfMemoryException이 발생합니다. 다음은이 코드를 작성하는 방법입니다.비트 맵 축소판 ArrayList 만들기
public ArrayList<Bitmap> createThumbnails() {
ArrayList<Bitmap> result = new ArrayList<Bitmap>();
for(int i = 0; i < NUM_PAGES; i++) {
//Bitmaps will be loaded here by resource, they're called w_0, w_1, w_2...
Bitmap b0 = BitmapFactory.decodeResource(getResources(), getResources().getIdentifier("w_" + i, "drawable", getPackageName()));
//Here the thumbnail gets created with new Dimensions (screenWidth and screenHeight)
Bitmap b1 = Bitmap.createBitmap(b0, 0, 0, screenWidth, screenHeight);
//The full-sized Bitmap gets recycled to gain some memory back
b0.recycle();
//The resized Bitmap 'b1' gets added to the ArrayList and the loop repeats
result.add(b1);
}
return result;
}
더 나은 방법이 있습니까? 서로 다른 비율의 배경 화면이 있습니다. 난이 벽지에서 잘라낸 화면의 크기를 전체 화면으로 보여 주기만하면됩니다. 이것을 어떻게 할 수 있습니까?
미리 감사드립니다.
이 방법은 메모리를 소비합니다. 보십시오 : http://stackoverflow.com/a/18015841/1531054 –