我正在制作一个应用程序,您可以在其中单击按钮并拍照,然后在拍照后我想在图像视图中显示它。
我为此使用此代码:
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Button b = (Button) getView().findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} catch(ActivityNotFoundException e){
Toast.makeText(getActivity(), "Your device does not have a camera", Toast.LENGTH_SHORT).show();
}
}
});
send = (Button) getView().findViewById(R.id.button2);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Uploading image...", Toast.LENGTH_LONG).show();
new uploadtoserver().execute();
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (data != null) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) getView().findViewById(R.id.imageView1);
//image.setImageBitmap(thumbnail);
send.setVisibility(Button.VISIBLE);
// CALL THIS METHOD TO GET THE URI FROM THE BITMAP
Uri tempUri = getImageUri(getActivity(), thumbnail);
// CALL THIS METHOD TO GET THE ACTUAL PATH
finalFile = new File(getRealPathFromURI(tempUri));
Bitmap bmImg = BitmapFactory.decodeFile(finalFile.toString());
image.setImageBitmap(bmImg);
System.out.println(finalFile);
}
}
}
这是imageview的xml部分
但它显示图像被裁剪和丑陋(不是原始尺寸)
如何让它在imageview中显示照片的原始大小?