我一直试图在捕获后将图像数据传回应用程序。但是,尝试返回到我的应用程序时,它总是崩溃。无法将图像数据传递回Android应用程序
的代码开始的意图是:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgView = (ImageView) findViewById(R.id.ImageView);
upload = (Button) findViewById(R.id.Upload);
snap = (Button) findViewById(R.id.Snap);
select = (Button) findViewById(R.id.Select);
subject = (EditText) findViewById(R.id.Subject);
msg = (EditText) findViewById(R.id.Message);snap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String imageFilePath = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/picture.jpg";
File imageFile = new File(imageFilePath);
Uri imageFileUri = Uri.fromFile(imageFile); // convert path to Uri
Intent it = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
it.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(it, CAMERA_RESULT);
}
});
}
接收意向的代码是:
case CAMERA_RESULT:
if (resultCode == Activity.RESULT_OK) {
// Get Extra from the intent
Bundle extras = data.getExtras();
// Get the returned image from extra
Bitmap bmp = (Bitmap) extras.get("data");
imgView = (ImageView) findViewById(R.id.ImageView);
imgView.setImageBitmap(bmp);
}
break;
我也收到以下例外情况发生应用程序崩溃时:
java.lang.RuntimeException:无法恢复活动{com.NYP.estatemanagement/com.NYP.estatemanagement.MainActivity}: java.lang.RuntimeException:将结果ResultInfo {who = null,request = 100,result = -1,data = null}传递给activity {com.NYP.estatemanagement/com.NYP.estatemanagement.MainActivity}:java.lang。 NullPointerException异常
谢谢!它设法将图像数据发送回应用程序而不会崩溃。我可以再问两个问题吗?有没有办法让图像尺寸变大?第二个问题:有没有一种方法可以持久存储当方向发生变化或应用程序从暂停状态返回时显示图像?再次感谢帮助= D – Benflop