我已經通過Intent實現了Camera並在Imageview中設置該圖像顯得模糊,而在ImageGallery中相同的圖像顯示清晰。該代碼和相關圖片如下:Imageview中的模糊圖像問題
活動課:
public class MainActivity extends ActionBarActivity {
Button b1,b2;
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
iv=(ImageView)findViewById(R.id.imageView);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Bitmap bp = (Bitmap) data.getExtras().get("data");
iv.setImageBitmap(bp);
}
文件被保存在SD卡,也是我retrive其URI成功地,但仍ImageView的當相機點擊並返回時,不顯示此圖像或imageview消失。代碼如下 - :
public class MainActivity extends Activity {
static int TAKE_PIC =1;
Uri outPutfileUri;
ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.image);
}
public void CameraClick(View v) {
Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"MyPhoto.jpg");
outPutfileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outPutfileUri);
startActivityForResult(intent, TAKE_PIC);
}
Bitmap bitmap = null;
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent data)
{
if (requestCode == TAKE_PIC && resultCode==RESULT_OK) {
String uri = outPutfileUri.toString();
Log.e("uri-:", uri);
mImageView.setImageURI(Uri.parse(uri));
}
}}
請告訴我如何獲取點擊圖像的路徑,並將其設置爲imageview。我剛來這地方。
你能描述什麼問題? –
它確實有幫助。謝謝 –