ImageView.setImageBitmap(位图),但屏幕上只有空白

时间:2015-03-27 17:33:34

标签: android bitmap imageview

// private File file;

// c_img = (ImageView) findViewById(R.id.c_img);

file = new File(
                Environment.getExternalStorageDirectory().getAbsoluteFile()
                + "/" + getTime() + ".jpg");
        iImg.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        startActivityForResult(iImg, 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == 1) {
        Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
        c_img.setImageBitmap(bitmap);
    }
}

// getTime()返回当前的本地时间。

// xml是:

<ImageView 
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:id="@+id/c_img"/>

谢谢!

0 个答案:

没有答案