-2
我是android新手。我的问题是如何在图像视图中设置共享首选项。我想将图片分享给其他活动。请帮助我,因为我储存了它..请帮我解释清楚和代码。谢谢。图片视图共享偏好
我是android新手。我的问题是如何在图像视图中设置共享首选项。我想将图片分享给其他活动。请帮助我,因为我储存了它..请帮我解释清楚和代码。谢谢。图片视图共享偏好
跨活动共享数据的“标准”方式是将putExtraXXX方法用于intent类。你可以把图片的路径在你的意图:
Intent intent = new Intent(this,MyClassA.class);
intent.putExtra(MyClassA.IMAGE_EXTRA, imagePath);
startActivity(intent);
你找回它,在你的下一个活动打开它:
String filePath = getIntent().getStringExtra(MyClassA.IMAGE_EXTRA);
这里是打开和图像解码和功能的实现返回一个Bitmap对象,注意这个函数要求图像位于资产文件夹中:
private Bitmap getImageFromAssets(String assetsPath,int reqWidth, int reqHeight) {
AssetManager assetManager = getAssets();
InputStream istr;
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
istr = assetManager.open(assetsPath);
bitmap = BitmapFactory.decodeStream(istr, null, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(istr, null, options);
} catch (IOException e) {
return null;
}
return bitmap;
}
是你想要的吗? http://stackoverflow.com/questions/18041575/android-how-can-i-transfer-imageview-from-one-activity-to-another-activity/18041651#18041651 – Luc