浏览图像不适用于捕获的图片

时间:2014-03-14 16:21:19

标签: android android-image

我是Android的新手,在我的应用中,我想将图库中的图片添加到我的活动中。我用Google搜索,并得到一些代码。但该代码不适用于我在Android设备中捕获的图片。我的设备是Xperia S.而且我不知道那是因为高分辨率还是其他东西。我不知道它是什么。我的代码是:

Button buttonSelectImage = (Button) findViewById(R.id.ButtonSelect);
    buttonSelectImage.setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {

            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, PICK_IMAGE);

        }

    });

protected void onActivityResult(int requestCode, int resultCode,
        Intent intent) 
{
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode) 
    {

        case (PICK_IMAGE):
            if (resultCode == RESULT_OK) 
            {

                Uri photoUri = intent.getData();
                if (photoUri != null) 
                {

                        TextView t = (TextView) this
                                .findViewById(R.id.EditTextImage);

                        Cursor cursor = getContentResolver().query(
                                photoUri, null, null, null, null);
                        cursor.moveToFirst();

                        int idx = cursor
                                .getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                        absoluteFilePathSource = cursor.getString(idx);
                        t.setText(absoluteFilePathSource);

                        BitmapFactory.Options opt = new BitmapFactory.Options();
                        opt.inDither = false;
                        opt.inScaled = false;
                        opt.inDensity = 0;
                        opt.inJustDecodeBounds = false;
                        opt.inPurgeable = false;
                        opt.inSampleSize = 1;
                        opt.inScreenDensity = 0;
                        opt.inTargetDensity = 0;

                        sourceBitmap = BitmapFactory.decodeFile(absoluteFilePathSource,
                                opt);
                }
            }
            break;

    }
}

请有人帮我找到错误。请..提前谢谢

0 个答案:

没有答案