http://www.c-sharpcorner.com/UploadFile/9e8439/how-to-make-a-custom-camera-ion-android/我制作了一个自定义相机应用程序,点击图片后我想在图片视图中预览它,但是当我在图片视图中预览时,图片正在从图片的实际尺寸缩放。 / p>
答案 0 :(得分:0)
他是我让它为我工作的方式!假设您正在捕获图像,并希望在新的活动中显示捕获的图像,您可以按照这种方式:
首先点击按钮,您可以:
public void cameraFuture(View view) // <-- onClick() method of Camera Button
{
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);
}
然后在onActivityResult()
方法上,您可以这样做:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PIC && resultCode==RESULT_OK){
Toast.makeText(this, outPutfileUri.toString(),Toast.LENGTH_LONG).show();
Intent bitIntent = new Intent(this, CameraTake.class);
bitIntent.putExtra("imageUri", outPutfileUri);
startActivity(bitIntent);
finish();
}
}
在下一个Activity中,您可以通过以下方式接收文件:
Intent receiveIntent = getIntent();
uri = receiveIntent.getParcelableExtra("imageUri");
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
receiveImg= null;
} else {
receiveImg= extras.getString("PASSER");
}
} else {
receiveImg= (String) savedInstanceState.getSerializable("PASSER");
}
File imgFile = new File(Environment.getExternalStorageDirectory(),"MyPhoto.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.camOut);
myImage.setImageBitmap(myBitmap);
}
希望它有所帮助!
答案 1 :(得分:-1)
This link完全描述了你想要的东西。以下是摘要:
1-将此添加到Manifest:
< uses-feature android:name="android.hardware.camera" android:required="true" />
2-将此行添加到您的班级:
static final int REQUEST_IMAGE_CAPTURE = 1;
3-在你要打开相机的地方调用此方法:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
4-覆盖onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ImageView ivImage = (ImageView) findViewById(R.id.ivImage);
ivImage.setImageBitmap(imageBitmap);
}
}
我希望它可以帮到你。