Search code examples
androidurlbitmappanoramas

URL to Bitmap for PanoramaGL viewer


I'm working on an app that should connect to a URL, retrieve the image as Bitmap and then show it in a viewer based on PanoramaGL library.

The problem is that even if Log says that the image is catched, the display remains blank.

Here is the code I'm using to retrieve the bitmap also following the very detailed answer I found there How to load an ImageView by URL in Android?. -- in fact i'd like to read the image directly without cache or so on.

As you will see most parts of codes are taken from online tutorials as I'm just starting developping.

PanoramaActivity.java (in order to test it can be used as the MainActivity)

import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.panoramagl.PLImage;
import com.panoramagl.PLSpherical2Panorama;
import com.panoramagl.PLView;

public class PanoramaActivity extends PLView {

Private static final String TAG = "+++++++++++++++";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.panorama_activity_main);
    new DownloadImageTask(this).execute("http://www.pianetacellulare.it/UserFiles/image/Android/Jelly%20Bean/photo_sphere_esempio.jpg");
}

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {

    PanoramaActivity pan;

    public DownloadImageTask(PanoramaActivity act) {
        this.pan = act;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        Log.d(TAG,"onPostExecute");
        PLSpherical2Panorama panorama = new PLSpherical2Panorama();
        panorama.setImage(new PLImage(result));
        pan.setPanorama(panorama);
    }
}   
}

I've created the constructor passing PanoramaActivity as I suppose that the app flow until onPostExecute method and there I need to find a way to display the image. If I'm wrong or there are any better ways please let me know.

I'm posting also panorama_activity_main.xml layout for tests:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".PanoramaActivity" >
</RelativeLayout>

Any hints appreciated, thanks in advance :)

UPDATE. I tried the same AsyncTask class using ImageView instead of PLView, and the image came out, so the download of the image is correctly done.. There is something in the use of PanoramaGL which is incorrect


Solution

  • remove

    setContentView(R.layout.panorama_activity_main);
    

    it is overwriting image. --> even if I do not undestand why this happens

    And above all.. be sure that the image you are linking to follows requirement:

    PanoramaGL only supports images with sizes at power of two e.g. 2048x1024, 1024x1024, 1024x512, 512x512, 512x256, 256x256, 256x128.