從一個(gè)活動(dòng)傳遞圖像另一個(gè)活動(dòng)SO上也有類似的問(wèn)題,但沒(méi)有一個(gè)對(duì)我有用。我想在Activity1中獲取單擊的圖像并在Activity2中顯示它。我正在獲取點(diǎn)擊圖像的圖像ID,如下所示:((ImageView) v).getId()并通過(guò)意圖將其傳遞給另一個(gè)活動(dòng)。在第二個(gè)活動(dòng)中,我使用圖像ID如下:imageView.setImageResource(imgId);我在兩個(gè)活動(dòng)中記錄了值og image id并且它是相同的。但我得到以下異常:android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f050000}我想這里的問(wèn)題getId()是返回Id ImageView而不是它的源圖像。所有這些圖像都存在于drawable。任何幫助贊賞。
3 回答

德瑪西亞99
TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊
這不行。你必須這樣試試。
將ImageView的DrawingCache設(shè)置為true,然后將背景保存為Bitmap并通過(guò)putExtra傳遞。
image.setDrawingCacheEnabled(true);Bitmap b=image.getDrawingCache();Intent i = new Intent(this, nextActivity.class);i.putExtra("Bitmap", b);startActivity(i);
在你的下一個(gè)活動(dòng)中,
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("Bitmap");imageView.setImageBitmap(bitmap);

紫衣仙女
TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
Drawable
在Application
類中定義靜態(tài)變量,然后在第一個(gè)活動(dòng)中設(shè)置圖像可繪制數(shù)據(jù),然后在下一個(gè)活動(dòng)中從您在Application
類中定義的靜態(tài)變量中獲取數(shù)據(jù)。
public class G extends Application { public static Drawable imageDrawable; ...}
第一項(xiàng)活動(dòng):
G.imageDrawable = imageView.getDrawable();
SecondActivity:
imgCamera.setImageDrawable(G.imageDrawable);
并在onDestroy中:
@Overrideprotected void onDestroy() { G.imageDrawable = null; super.onDestroy();}
注意:您必須Application
在清單中定義您的類:
<application android:name=".G" ...></application>
- 3 回答
- 0 關(guān)注
- 517 瀏覽
添加回答
舉報(bào)
0/150
提交
取消