简体   繁体   English

如何在Android活动中加载图片。

[英]How to Load an image in an activity in android.

This code save the image in " MyApp ".but how to load the image in other activity 此代码将图像保存在“ 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);

Well, if you have defined the BitMap variable as a data member of your MyApp class, you can easily fetch it in other activities by using a getter() function to fetch that BitMap image which you are storing in MyApp. 好吧,如果您已将BitMap变量定义为MyApp类的数据成员,则可以通过使用getter() function来获取要存储在MyApp中的BitMap图像来轻松地在其他活动中获取它。

Or, you could pass your image along with Intent, by encoding it into String format. 或者,您可以将图像与Intent一起传递,方法是将其编码为String格式。

If you know the absolute path of the file. 如果您知道文件的绝对路径。 You can use BitmapFactory.decodeFile(filePath, opts) method to get the Bitmap. 您可以使用BitmapFactory.decodeFile(filePath, opts)方法获取Bitmap。 Then use ImageView's method setImageBitmap() to show it. 然后使用ImageView的方法setImageBitmap()进行显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM