이 난 캐시에 비트 맵을 넣어 만든 방법 ..처음 비트 맵을 넣고 캐시에서로드하는 방법은 무엇입니까?
//Caching method to cache images loaded from the URL's.
public void putBitmapInDiskCache(URI imageUri, Bitmap avatar) {
File cacheDir = new File(MainMenu.this.getCacheDir(), "thumbnails");
cacheDir.mkdirs();
File cacheFile = new File(cacheDir, ""+imageUri.hashCode());
try {
cacheFile.createNewFile();
FileOutputStream fos = new FileOutputStream(cacheFile);
avatar.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (Exception e) {
Log.e("error", "Error when saving image to cache. ", e);
}
}
유일한 문제는이 다운로드 될 때 초기 나 비트 맵 폭 및 높이 파라미터 설정되어있다. 그러나 캐시에 넣고 당기면 너비와 높이가 줄어들고 커지게됩니다. 화면에서 스크롤하면 올바르게 다시 설정됩니다. intially 그것의 너비와 높이를 잃는다.
편집 : 내 getimagefromCache() 메서드를 사용하여 비트 맵을로드합니다.
public void getImagesfromCache() throws MalformedURLException{
if(new File(new File(this.getApplicationContext().getCacheDir(), "thumbnails"),"" + imageCacheUri.hashCode()).exists()){
String cacheFile = this.getApplicationContext().getCacheDir() +"/thumbnails/"+ imageCacheUri.hashCode();
ImageView i = new ImageView(this.getApplicationContext());
FileInputStream fis = null;
try {
fis = new FileInputStream(cacheFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(fis);
i.setImageBitmap(bm);
i.setTag(mImageURLs);
putBitmapInDiskCache(imageCacheUri, bm);
//Set the BaseAdapter to a gallery, holding the images
((Gallery) findViewById(R.id.gallery))
.setAdapter(new ImageAdapter(MainMenu.this));
어떻게 비트 맵 이미지를로드합니까? 코드를 보면 더 좋아질 것입니다 – Ronnie
내 편집을 확인하십시오 – yoshi24
get에 putBitmapInDiskCache를 호출하는 이유는 무엇입니까? – Ronnie