Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Andengine将位图附加到场景_Java_Android_Bitmap_Andengine_Game Engine - Fatal编程技术网

Java Andengine将位图附加到场景

Java Andengine将位图附加到场景,java,android,bitmap,andengine,game-engine,Java,Android,Bitmap,Andengine,Game Engine,我正在做一个游戏,我正在用Facebook登录。我遇到的问题是,当我下载图像时,它是一个位图,我不知道如何在场景中显示位图 我是个新手,希望有人能帮我 /** * The actual AsyncTask that will asynchronously download the image. */ class ProfileImageDownloaderTask extends AsyncTask<String, Void, Bitmap> { private Stri

我正在做一个游戏,我正在用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;
}
/**
*将异步下载映像的实际异步任务。
*/
类ProfileImageDownloaderTask扩展异步任务{
私有字符串url;
私人雪碧;
公共档案图像下载任务(雪碧雪碧){
this.sprite=精灵;
}
/**
*实际下载方法。
*/
@凌驾
受保护位图doInBackground(字符串…参数){
url=params[0];
返回下载图像(url);
}
/**
*下载图像后,请对其进行处理
*/
@凌驾
受保护的void onPostExecute(位图){
将图像保存到内部存储器(位图);
}
}
公共位图下载图像(字符串url){
位图图像=空;
试一试{
InputStream in=new java.net.URL(URL.openStream();
image=BitmapFactory.decodeStream(in);
}捕获(例外e){
Log.e(“Error”,e.getMessage());
e、 printStackTrace();
}
返回图像;
}
希望我能得到一些答案:)

应该有用

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

应该起作用

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