如何加载从画廊的图像视图的图像?图像、视图、画廊、加载

2023-09-05 02:43:42 作者:依舊悲傷落

我有一个活动,其中有一个按钮。当我按一下按钮它重定向我的图片库。我想使用图像视图,以显示在下一个活动的选择的图像。但它不显示图像。视图是关闭时,图像设置屏幕。

I have an activity, which has a button. When I click on the button it redirects me to the image gallery. I want to show the selected image in the next activity using an image view. But it is not displaying the image. The view is off screen when the image is set.

我的code选择图像和运动对下一如下。我使用没有历史在我的活动真的。

My code for selecting image and moving on next is given below. I am using no history true in my activities.

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
            && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        if (!(picturePath.equals(""))) {
            Intent intent = new Intent();
            intent.setClass(MainActivity.this, ImageInGellary.class);
            intent.putExtra("picturePath", picturePath);
            startActivity(intent);

        }
    }
}

公共类ImageInGellary延伸活动{     按钮来取消;

public class ImageInGellary extends Activity { Button cancel;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.load_image);
    cancel = (Button) findViewById(R.id.buttonCancelPicture);
    Intent in = getIntent();
    savedInstanceState = in.getExtras();
    String picturePath = savedInstanceState.getString("picturePath");
    ImageView imageView = (ImageView) findViewById(R.id.img_view);
    imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
    cancel.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            /*
             * Intent i = new Intent(Intent.ACTION_PICK,
             * android.provider.MediaStore
             * .Images.Media.EXTERNAL_CONTENT_URI);
             * 
             * startActivityForResult(i, RESULT_LOAD_IMAGE);
             */
            Intent intent = new Intent();
            intent.setClass(ImageInGellary.this, MainActivity.class);
            startActivity(intent);

        }
    });
}

}

推荐答案

的 http://tjkannan.blogspot.in/2012/01/load-image-from-camera-or-gallery.html

http://www.$c$crzheaven.com/2012/04/20/select-an-image-from-gallery-in-android-and-show-it-in-an-imageview/

查阅这些links.It的帮助ü。

Check out these links.It's help u.