我正在开发一个使用 Facebook 登录的游戏。我遇到的问题是当我下载图像时它是位图,我不知道如何在场景上显示位图。
我对此很陌生,希望有人可以帮助我!
/**
* 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;
}
希望我能得到一些答案:)