I am working on a game where i am logging in with Facebook. The problem i got is when i download the Image it is a Bitmap and i have no idea how to show a Bitmap on the Scene.
I am fairly new to this and hope somebody can help me with this!
/**
* The actual AsyncTask that will asynchronously download the image.
*/
class ProfileImageDownloaderTask extends AsyncTask<String, Void, Bitmap> {
private String url;
private Sprite sprite;
public ProfileImageDownloaderTask(Sprite sprite) {
this.sprite = sprite;
}
/**
* Actual download method.
*/
@Override
protected Bitmap doInBackground(String... params) {
url = params[0];
return downloadImage(url);
}
/**
* Once the image is downloaded, do something with it
*/
@Override
protected void onPostExecute(Bitmap bitmap) {
saveImageToInternalStorage(bitmap);
}
}
public Bitmap downloadImage(String url) {
Bitmap image = null;
try {
InputStream in = new java.net.URL(url).openStream();
image = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return image;
}
Hope i get some answers :)