1

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

Community
  • 1
  • 1
Lucia Belardinelli
  • 727
  • 1
  • 11
  • 20
  • 1
    Are you sure the bitmap is downloaded correctly and not corrupted? You could write it to file and/or display in a normal ImageView. Using onPostExecute is ok. – greenapps May 14 '14 at 21:44
  • Hi, thanks for replying. How can I check if it's corrupted? As I need to display the image without storing i'll try also the ImageView as you suggested. But if you have any particular idea on how to solve this directly with PanoramaGL it's better as, looking forward, it has a very nice utility for the implementation of gyroscope controls and even simulated gyroscope controls :) – Lucia Belardinelli May 15 '14 at 07:07
  • @greenapps About ImageView, I found this "There is no way to get an interactive photo sphere in your Activity" .. so I need to go on with PanoramaGL. Thanks for help anyway. – Lucia Belardinelli May 15 '14 at 08:28
  • 1
    Save mIcon11 to file. Take a File Manager and browse to it. Then let it open in an ImageViewer. Then you know if it is corrupted. – greenapps May 15 '14 at 11:55

2 Answers2

1

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.

Lucia Belardinelli
  • 727
  • 1
  • 11
  • 20
  • PanoramaGL only supports images with sizes at power of two e.g. 2048x1024, 1024x1024, 1024x512, 512x512, 512x256, 256x256, 256x128. How can i extend PanoramaGL to another format.? – tamtoum1987 Dec 26 '14 at 08:55
0

Use Image loader

private void loadPanorama()
    {
        try
        {
            final Context context = this.getApplicationContext();
            PLIPanorama panorama = null;
            //Lock panoramic view
            this.setLocked(true);


            Toast.makeText(context, "image loader start", Toast.LENGTH_LONG).show();
            imageLoader.loadImage("http://104.245.38.221/www/200/000/005/2000000057042/f/z_0/00.jpg", new SimpleImageLoadingListener()  
            { 
                @Override 
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
                { 
                    cubicPanorama.setImage(new PLImage(loadedImage, false), PLCubeFaceOrientation.PLCubeFaceOrientationFront);
                } 
            }); 
            imageLoader.loadImage("http://104.245.38.221/www/200/000/005/2000000057042/b/z_0/00.jpg", new SimpleImageLoadingListener()  
            { 
                @Override 
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
                { 
                    cubicPanorama.setImage(new PLImage(loadedImage, false), PLCubeFaceOrientation.PLCubeFaceOrientationBack);
                } 
            }); 
            imageLoader.loadImage("http://104.245.38.221/www/200/000/005/2000000057042/l/z_0/00.jpg", new SimpleImageLoadingListener()  
            { 
                @Override 
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
                { 
                    cubicPanorama.setImage(new PLImage(loadedImage, false), PLCubeFaceOrientation.PLCubeFaceOrientationLeft);
                } 
            }); 
            imageLoader.loadImage("http://104.245.38.221/www/200/000/005/2000000057042/r/z_0/00.jpg", new SimpleImageLoadingListener()  
            { 
                @Override 
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
                { 
                    cubicPanorama.setImage(new PLImage(loadedImage, false), PLCubeFaceOrientation.PLCubeFaceOrientationRight);
                } 
            }); 
            imageLoader.loadImage("http://104.245.38.221/www/200/000/005/2000000057042/u/z_0/00.jpg", new SimpleImageLoadingListener()  
            { 
                @Override 
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
                { 
                    cubicPanorama.setImage(new PLImage(loadedImage, false), PLCubeFaceOrientation.PLCubeFaceOrientationUp);
                } 
            }); 
            imageLoader.loadImage("http://104.245.38.221/www/200/000/005/2000000057042/d/z_0/00.jpg", new SimpleImageLoadingListener()  
            { 
                @Override 
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
                { 
                    cubicPanorama.setImage(new PLImage(loadedImage, false), PLCubeFaceOrientation.PLCubeFaceOrientationDown);
                } 
            }); 

            panorama = cubicPanorama;
            Toast.makeText(context, "image loader end", Toast.LENGTH_LONG).show();

            if(panorama != null)
            {
                //Set camera rotation
                panorama.getCamera().lookAt(0.0f, 170.0f);
                //Add a hotspot
                //panorama.addHotspot(new PLHotspot(1, new PLImage(PLUtils.getBitmap(context, R.raw.hotspot), false), 0.0f, 170.0f, 0.05f, 0.05f));
                //Reset view
                this.reset();
                //Load panorama
                this.startTransition(new PLTransitionBlend(2.0f), panorama); //or use this.setPanorama(panorama);
            }
            //Unlock panoramic view
            this.setLocked(false);
        }
        catch(Throwable e)
        {
            Toast.makeText(this.getApplicationContext(), "Error: " + e, Toast.LENGTH_SHORT).show();
        }
    }

If black screen appears you can override

@Override
public void onLoadingStarted(String imageUri, View view) {
if (frontBitamp != null) {
cubicPanorama.setImage(new PLImage(frontBitamp, false),
PLCubeFaceOrientation.PLCubeFaceOrientationFront);
}};
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
cubicPanorama.setImage(new PLImage(loadedImage, false),
PLCubeFaceOrientation.PLCubeFaceOrientationFront);
frontBitamp = loadedImage;}