1

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 :)

4

1 に答える 1

4

This should work.

I see you are saving the image (saveImageToInternalStorage(bitmap);). So if the first option I gave you doesn't work, you can use an official class of AndEngine instead: FileBitmapTextureAtlasSource.

于 2012-12-01T00:07:45.497 に答える