从图库加载图片,返回错误

时间:2015-02-04 00:12:07

标签: android android-activity

我正在从图库中加载图片,然后我正在处理图像然后将其加载到图像视图,一切正常,当我想从图库中选择图片时,然后我想取消,我有一个错误,我无法解决它。

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profil);
    Parse.initialize(this, "I8Av35RZ0QQaOCA3uc84BmSdkOMpIzPNZI2pvcqV", "abBzfNsr6RG9AiYLuO3NImhvcZmTV6QgqKJgAANc");
    nom = (EditText) findViewById(R.id.editText1);
    profil = (ImageView) findViewById(R.id.imageView1);
    profil.setOnClickListener(this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.profil, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.blink);
    profil.startAnimation(hyperspaceJumpAnimation);
    Intent intent = new Intent();
 // call android default gallery
 intent.setType("image/*");
 intent.setAction(Intent.ACTION_GET_CONTENT);
 // ******** code for crop image
 intent.putExtra("crop", "false");
 intent.putExtra("aspectX", 200);
 intent.putExtra("aspectY", 200);
 intent.putExtra("outputX", 150);
 intent.putExtra("outputY", 150);
 intent.putExtra("scale", true);
 intent.putExtra("scaleUpIfNeeded", true);
 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

 try {

 intent.putExtra("return-data", true);
 startActivityForResult(Intent.createChooser(intent,
 "Complete action using"), PICK_FROM_GALLERY);

 } catch (ActivityNotFoundException e) {
 // Do nothing for now
 }





}  

protected void onActivityResult(int requestCode, int resultCode, Intent data) {



Bundle extras2 = data.getExtras();
if (extras2 != null) {
Bitmap photo = extras2.getParcelable("data");
profil.setImageBitmap(photo);

}



  }     

}

1 个答案:

答案 0 :(得分:0)

检查onActivityResult中的结果代码。如果它没有返回OK,则不要处理返回的意图。