I'm trying to get a photosphere image from server which run PHP. I fetch the image using the universal image loader library. And then, after I got the bitmap, I save it to the sd card, and then on other activity, I try to open the photosphere image using the gallery. the problem is that when I saved the image, it is compressed form 6MB to only less than 1MB which causes the gallery cannot open the photosphere image. is there any way to solve this? (I was wondering if it is possible to pass the bitmap directly to gallery or there is a method to save the image uncompressed)
the code :
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheInMemory(true).cacheOnDisk(true)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
.defaultDisplayImageOptions(defaultOptions)
.build();
ImageLoader.getInstance().init(config);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(mHotelDetailResponseData.photosphere, mImage, defaultOptions, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
Log.d("Test","fail : " + failReason.getCause().getMessage());
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
Log.d("Test","complete");
writeBitmapToMemory(loadedImage);
mPhotoSphereButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("test","can continue");
Intent i = new Intent(getActivity(), PhotosphereActivity.class);
startActivityForResult(i,0);
}
});
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
Log.d("Test","progress:" +current+"/"+total);
}
});
private void writeBitmapToMemory(Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
Log.d("test","written to : " + Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
} catch (IOException e) {
e.printStackTrace();
Log.d("test","error : " + e.getMessage());
}
}
the activity that send an intent to open it in gallery : (works okay if I open the uncompressed photosphere)
public class PhotosphereActivity extends BaseActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startPanorama();
}
private void startPanorama() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.google.android.gms", "com.google.android.gms.panorama.PanoramaViewActivity"));
intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory() + File.separator + "test.jpg"), "image/*");
startActivity(intent);
}