2014-09-26 25 views
0

在Android應用.. 我的要求是: - 我有120dp X 120dp大小的空間,我的活動.. 我希望當我點擊這個空間它將顯示選項: -如何在android程序中設置內存中的圖像?

  1. 電話存儲器

  2. SD卡

我可以選擇任何them.from的有我可以選擇(在一個時間只有1人)的任何圖像.. 甲選擇它將設置在120dp X 120dp大小..

我已閱讀http://developer.android.com/training/displaying-bitmaps/index.html但我無法理解我如何調用內存? 1)手機內存和2)SD卡..

回答

0

您可以使用此負載位圖:

ImageView imgInternal = (ImageView) findViewById(R.id.imgInternal); 
ImageView imgExternal = (ImageView) findViewById(R.id.imgExternal); 
String internal = context.getFilesDir().getAbsolutePath() + "/" + "img.png"; // For internal storage 
String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "img.png"; // For external storage 
Bitmap bmpExternal = BitmapFactory.decodeFile(external); // For external 
Bitmap bmpInternal = BitmapFactory.decodeFile(internal); // For internal 
imgExternal.setImageBitmap(bmpExternal); 
imgInternal.setImageBitmap(bmpInternal); 

外部存儲,您應該添加這AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+0

BMP位圖= BitmapFactory。 decodeFile(外部); 位圖bmp = BitmapFactory.decodeFile(internal); 這是說「重複本地變量bmp」 – 2014-09-26 08:36:49

+0

你必須選擇一個,內部或外部,如果你想使用兩個內存,你應該改變一個位圖變量的名稱。我正在編輯我的答案。 – RdlP 2014-09-26 08:38:52

+0

但是從一個imageview我不能得到兩個選項? PH存儲器和SD卡存儲器選擇任何一個。 – 2014-09-26 08:42:12

相關問題