图像查看共享preferences [英] image view Shared preferences
问题描述
我在Android的新手。我的问题是如何设置图像查看共享preferences。我想分享图片到另一个活动。请帮我,因为我在放养吧..请帮我解释一下我清楚,codeS。谢谢你。
I'm newbie in android. My question is how to set shared preferences in image view. I want to shared the image to another activity. Please help me because I'm stocked on it.. Please help me the explain me clearly and codes. Thank you.
推荐答案
标准的方式来分享整个活动数据usign的意图类putExtraXXX方法。你可以把图片的路径在你的意图:
The "standard" way to share data across Activities is usign the putExtraXXX methods on the intent class. You can put the image path in your intent:
Intent intent = new Intent(this,MyClassA.class);
intent.putExtra(MyClassA.IMAGE_EXTRA, imagePath);
startActivity(intent);
和您检索它和你的下一个活动打开它:
And you retrieve it and open it in your next Activity:
String filePath = getIntent().getStringExtra(MyClassA.IMAGE_EXTRA);
下面是打开和德codeS影像并返回一个位图对象的函数的实现,注意此功能需要图像位于资产文件夹:
Here is an implementation of a function that opens and decodes the image and return a Bitmap object, notice that this function requires the image to be located in the assets folder:
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;
}
这篇关于图像查看共享preferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!