0

我正在尝试在新活动的 ImageView 中显示图像,但我遇到了问题。新活动已打开,我可以在 toast 消息中看到图像的路径,但仍然看不到图像!有什么问题?

MainActivity 类的一部分:

       gridview.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int position, long id) {

            String[] projection = {MediaStore.Images.Media.DATA};
            cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
            int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToPosition(position);
            String imagePath = cursor.getString(columnIndex);

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), FullImageActivity.class);

            i.putExtra("image", imagePath);

            //Toast.makeText(MainActivity.this, "" + imagePath, Toast.LENGTH_SHORT).show();

            startActivity(i);
        }
    });

全活动类:

public class FullImageActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    //int id = i.getExtras().getInt("image");
    //ImageAdapter imageAdapter = new ImageAdapter(this);
    String imageId = i.getExtras().getString("image");

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
    imageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageId));
    //imageView.setImageResource(imageAdapter.mThumbIds[position]);

    Toast.makeText(FullImageActivity.this, "" + imageId, Toast.LENGTH_LONG).show();
}
}
4

1 回答 1

0

试试这个。

FullActivity.java

Bitmap bitmap =BitmapFactory.decodeFile(imageId);
imageView.setImageBitmap(bitmap);

请让我知道这对你有没有用..

快乐编码:)

于 2013-02-17T11:25:54.887 回答