I have an equirectangular image like this:
I have the image in my AssetsFolder, therefor I pass this uri to the Panorama.PanoramaApi.loadPanoramaInfo method:
Uri uri = Uri.parse("file:///android_asset/panorama/equi_1.jpg");
Somehow, if I check the result.getViewerIntent, I get null as return value.
My gut feeling says this could have to do with the fact that this image is not created with the google camera app, and therefor missing some meta tags, but I'm not sure.
The complete code of my PanoramaActivity:
public class PanoramaActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
public static final String PANORAMA_URI = "panorama_uri";
private GoogleApiClient gacClient;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gacClient = new GoogleApiClient.Builder(this, this, this)
.addApi(Panorama.API)
.build();
}
@Override
public void onStart() {
super.onStart();
gacClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
Intent intent = getIntent();
if (intent != null) {
String fileUri = intent.getStringExtra(PANORAMA_URI);
if (fileUri != null && !fileUri.isEmpty()) {
Uri uri = Uri.parse("file:///android_asset/panorama" + fileUri);
Panorama.PanoramaApi.loadPanoramaInfo(gacClient, uri).setResultCallback(
new ResultCallback<PanoramaApi.PanoramaResult>() {
@Override
public void onResult(PanoramaApi.PanoramaResult result) {
Intent i;
if (result.getStatus().isSuccess() && (i = result.getViewerIntent()) != null) {
startActivity(i);
} else {
// Handle unsuccessful result
}
}
});
} else {
finish();
}
} else {
finish();
}
}
@Override
public void onConnectionSuspended(int cause) {
// Handle connection being suspended
}
@Override
public void onConnectionFailed(ConnectionResult status) {
// Handle connection failure.
}
@Override
public void onStop() {
super.onStop();
gacClient.disconnect();
}
}
I think your gut is correct, Google probably requires metadata to parse the image.
Here's what I found.
This guy here mentions about using photoshop to embed xml metadata into a jpg.
<?xpacket begin='' id=''?><x:xmpmeta xmlns:x='adobe:ns:meta/'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<rdf:Description rdf:about="" xmlns:GPano="http://ns.google.com/photos/1.0/panorama/">
<GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>
<GPano:CaptureSoftware>Photo Sphere</GPano:CaptureSoftware>
<GPano:StitchingSoftware>Photo Sphere</GPano:StitchingSoftware>
<GPano:ProjectionType>equirectangular</GPano:ProjectionType>
<GPano:PoseHeadingDegrees>350.0</GPano:PoseHeadingDegrees>
<GPano:InitialViewHeadingDegrees>90.0</GPano:InitialViewHeadingDegrees>
<GPano:InitialViewPitchDegrees>0.0</GPano:InitialViewPitchDegrees>
<GPano:InitialViewRollDegrees>0.0</GPano:InitialViewRollDegrees>
<GPano:InitialHorizontalFOVDegrees>75.0</GPano:InitialHorizontalFOVDegrees>
<GPano:CroppedAreaLeftPixels>0</GPano:CroppedAreaLeftPixels>
<GPano:CroppedAreaTopPixels>0</GPano:CroppedAreaTopPixels>
<GPano:CroppedAreaImageWidthPixels>4000</GPano:CroppedAreaImageWidthPixels>
<GPano:CroppedAreaImageHeightPixels>2000</GPano:CroppedAreaImageHeightPixels>
<GPano:FullPanoWidthPixels>4000</GPano:FullPanoWidthPixels>
<GPano:FullPanoHeightPixels>2000</GPano:FullPanoHeightPixels>
<GPano:FirstPhotoDate>2012-11-07T21:03:13.465Z</GPano:FirstPhotoDate>
<GPano:LastPhotoDate>2012-11-07T21:04:10.897Z</GPano:LastPhotoDate>
<GPano:SourcePhotosCount>50</GPano:SourcePhotosCount>
<GPano:ExposureLockUsed>False</GPano:ExposureLockUsed>
</rdf:Description>
Over here the project shows an example of loading a jpg in the panorama api. I don't know how to read the metadata from that jpg, but I'd venture to say it will be pretty interesting for you and probably helpful. The jpg is in the raw assets folder.
来源:https://stackoverflow.com/questions/34991105/use-panoramaapi-with-custom-equirectangular-image-from-assets-folder