Android-将图像保存到内部存储器,并将其作为另一项活动的一部分加载到imageview中
我的应用程序有一个摄像头按钮。单击此按钮后,启动本机摄像头应用程序,用户可以拍照。如果用户接受图片点击复选标记,我想启动一个新的活动,在新屏幕上显示该图像。我试图像这样保存图像:File File=newfilethis.getFilesDir,filename;然后获取文件路径,并将路径作为字符串传递给我的新活动。在我的新活动中,我试图从以前的意图中检索文件路径,并使用它将图像加载到ImageView中。在写入将图像加载到ImageView中的位之前,我希望通过在新屏幕上的文本区域中打印文件路径字符串来检查文件路径字符串是否被传递。不幸的是,它似乎没有正确通过。任何帮助都将不胜感激。下面是我的代码片段。非常感谢您的帮助Android-将图像保存到内部存储器,并将其作为另一项活动的一部分加载到imageview中,image,android-intent,save,android-image,android-file,Image,Android Intent,Save,Android Image,Android File,我的应用程序有一个摄像头按钮。单击此按钮后,启动本机摄像头应用程序,用户可以拍照。如果用户接受图片点击复选标记,我想启动一个新的活动,在新屏幕上显示该图像。我试图像这样保存图像:File File=newfilethis.getFilesDir,filename;然后获取文件路径,并将路径作为字符串传递给我的新活动。在我的新活动中,我试图从以前的意图中检索文件路径,并使用它将图像加载到ImageView中。在写入将图像加载到ImageView中的位之前,我希望通过在新屏幕上的文本区域中打印文件路
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_use_camera);
// create Intent to take a picture and return control to the calling application
Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//start the image capture Intent
startActivityForResult(cameraintent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
String filename = "myfile";
//make sure the user clicked to accept the picture in the native camera app
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
{
//save image internally
File file = new File(this.getFilesDir(), filename);
//get the filepath
String filepath = file.getAbsolutePath();
//create the swatchintent
Intent Swatchintent = new Intent(this, DisplaySwatchActivity.class);
//pass filepath to the intent
Swatchintent.putExtra(EXTRA_MESSAGE, filepath);
//start the intent
startActivity(Swatchintent);
}
}
}
然后,我的下一个活动:
public class DisplaySwatchActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_swatch);
String filepath = this.getIntent().getStringExtra(UseCameraActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setText(filepath);
}
如果运行调试器,是否看到在DisplaySwatchaActivity中设置filepath变量内容?可能是文本对于TextView来说太长了。是的,它看起来就在那里..以/data/data/com.example.insieme/files/myfile的形式出现我没有意识到TextView有字符限制-你仍然认为这可能是问题所在吗?也许最好是尝试将图像本身加载到imageview中,而不是执行此中间步骤。我对这一点很陌生,所以我感谢你的帮助。不是文本视图无法获取字符数,而是长字符串的布局将其推离屏幕-它在那里,但看不见。