0
我有一個活動(主要活動),在這個活動中我有兩個佈局,一個佈局三個文本框和其他按鈕,當我點擊按鈕佈局成功轉換成位圖並保存在SD卡中,但我不知道這個保存的佈局位圖如何回到ONCreate Mathod中的其他活動中。 請幫助我,我在安卓如何檢索佈局位圖圖像到第二個活動
新這是我的第一個活動
Bitmap b;
TextView textView,textView1,textView2;
ImageView imageView;
LinearLayout view;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.img);
view = (LinearLayout) findViewById(R.id.ll);
textView = (TextView) findViewById(R.id.tv1);
textView1 = (TextView) findViewById(R.id.tv2);
textView2 = (TextView) findViewById(R.id.tv3);
button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
public final String TAG =null ;
@Override
public void onClick(View v) {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
b = view.getDrawingCache();
Intent data = null;
imageView.setImageBitmap(b);
String root = Environment.getExternalStorageDirectory()
.toString();
File myDir = new File(root + "/_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
File file = new File(myDir, fname);
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
Log.i(TAG, "" + file);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
現在如何保存的圖像將retrive進入第二個活動
public class Main2Activity extends AppCompatActivity {
ImageView imageView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ImageView mImgView = (ImageView)findViewById(R.id.img1);
}
}
的ImageView的http://stackoverflow.com/questions/2091465/how -do-i-pass-data-between-activities-in-android – Breavyn
把額外的和額外的不工作在我的場景 – user3588072
傳遞圖像的URI在SD卡上,或直接傳遞位圖http:// stackoverflow。 com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another – Breavyn