AsyncTaskの理解に問題があります。私はそれを取得し、サイズを変更してそれを返すことができるようにファイルの場所を送信しています。 BaseAdapter ListViewである自分のアクティビティからasynctaskクラスを呼び出すと、型の不一致が発生します。JavaのAsyncTaskからBitMapを取得する
私は実行からビットマップを返すことができると思った。私はonPostExecute()を使用する必要がなく、わからないだということを読んだか..
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.....
}
}
私が好き)(getViewメソッド内でこのクラスを呼び出しています:
ImageHandler imgHandler = new ImageHandler();
Bitmap bitMap;
bitMap = imgHandler.execute(filename);
エラー:
Type mismatch: cannot convert from AsyncTask to Bitmap
あなたが[Picasso](https://github.com/square/picasso)、[Glide](https://github.com/bumptech/glide)、[Fresco] https://github.com/facebook/fresco)またはその他の画像ローディングライブラリ –
誰かがグライドを提案しましたが、私はそれが自分自身を動作させる方法を学びたかったと思います。 – silversunhunter