1

我正在开发一个使用 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;
}

希望我能得到一些答案:)

4

1 回答 1

4

应该有效。

我看到您正在保存图像 ( saveImageToInternalStorage(bitmap);)。因此,如果我给您的第一个选项不起作用,您可以改用 AndEngine 的官方类:FileBitmapTextureAtlasSource

于 2012-12-01T00:07:45.497 回答