AsyncTask'ı anlamada sorun yaşıyorum. Bir dosya konumu gönderirim, böylece onu alabilir, yeniden boyutlandırabilir ve geri verebilir. Ben bir asalctask sınıfı benim bazAdapter ListView olan aktivitemden aradığımda, bir tür uyuşmazlığı alıyorum.Java'da AsyncTask uygulamasından döndürülen bir BitMap'in alınması
Bitmap'i yürütmeden döndürebileceğimi düşündüm. Ben OnPostExecute() kullanmak gerekir ama emin olduğumu okudum nasıl ..
public class ImageHandler extends AsyncTask<String, Void, Bitmap> {
Bitmap sizedBMP = null;
@Override
protected Bitmap doInBackground(String... params) {
File imgFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath(), "/"+params[0]+"/"+params[0]+".png");
if (imgFile.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgFile.toString());
int newWidth = 500;
sizedBMP = getResizedBitmap(bmp, newWidth);
}
else{
//set no image available
}
return sizedBMP;
}
@Override
// Once the image is downloaded, associates it to the imageView
protected void onPostExecute(Bitmap sizedBMP) {
}
public Bitmap getResizedBitmap(Bitmap bm, int newWidth) {
// Bitmap gets resized here.....
}
}
ben gibi) (GetView içinde bu sınıf sesleniyorum:
ImageHandler imgHandler = new ImageHandler();
Bitmap bitMap;
bitMap = imgHandler.execute(filename);
Hata:
Type mismatch: cannot convert from AsyncTask to Bitmap
[Picasso] (https://github.com/square/picasso), [Glide] (https://github.com/bumptech/glide), [Fresco] kullanmama nedenlerinden herhangi biri (https://github.com/facebook/fresco) veya başka bir resim yükleme kitaplığı? –
Birisi kayma önerdi, ama kendimi nasıl çalıştırılacağını öğrenmek istedim sanırım. – silversunhunter