Non ho abbastanza familiarità con Glide, ma sembra che se conosci la dimensione del bersaglio, puoi usare qualcosa del genere:
Bitmap theBitmap = Glide.
with(this).
load("http://....").
asBitmap().
into(100, 100). // Width and height
get();
Sembra che tu possa passare -1,-1e ottenere un'immagine a dimensione intera (basata esclusivamente su test, non può vederla documentata).
Nota into(int,int)restituisce a FutureTarget<Bitmap>, quindi devi avvolgerlo in un blocco di prova che copre ExecutionExceptione InterruptedException. Ecco un'implementazione di esempio più completa, testata e funzionante:
class SomeActivity extends Activity {
private Bitmap theBitmap = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// onCreate stuff ...
final ImageView image = (ImageView) findViewById(R.id.imageView);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Looper.prepare();
try {
theBitmap = Glide.
with(SomeActivity.this).
load("https://www.google.es/images/srpr/logo11w.png").
asBitmap().
into(-1,-1).
get();
} catch (final ExecutionException e) {
Log.e(TAG, e.getMessage());
} catch (final InterruptedException e) {
Log.e(TAG, e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void dummy) {
if (null != theBitmap) {
// The full bitmap should be available here
image.setImageBitmap(theBitmap);
Log.d(TAG, "Image loaded");
};
}
}.execute();
}
}
Seguendo il suggerimento di Monkeyless nel commento qui sotto (e questo sembra essere anche il modo ufficiale ), puoi usare un SimpleTarget, opzionalmente accoppiato con override(int,int)per semplificare notevolmente il codice. Tuttavia, in questo caso deve essere fornita la dimensione esatta (non è accettato nulla al di sotto di 1):
Glide
.with(getApplicationContext())
.load("https://www.google.es/images/srpr/logo11w.png")
.asBitmap()
.into(new SimpleTarget<Bitmap>(100,100) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
image.setImageBitmap(resource); // Possibly runOnUiThread()
}
});
come suggerito da @hennry se hai richiesto la stessa immagine, utilizzanew SimpleTarget<Bitmap>()