[英]How to Load an image in an activity in android.
此代碼將圖像保存在“ MyApp”中。但是如何在其他活動中加載圖像
final EditText txtRegid = (EditText)this.findViewById(R.id.regid);
String RegID = txtRegid.getText().toString();
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+RegID+".jpg");
String mSelectedImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
好吧,如果您已將BitMap變量定義為MyApp類的數據成員,則可以通過使用getter() function
來獲取要存儲在MyApp中的BitMap圖像來輕松地在其他活動中獲取它。
或者,您可以將圖像與Intent一起傳遞,方法是將其編碼為String格式。
如果您知道文件的絕對路徑。 您可以使用BitmapFactory.decodeFile(filePath, opts)
方法獲取Bitmap。 然后使用ImageView的方法setImageBitmap()進行顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.