Android 是否可以拍照(不保存到外部或内部存储器)并进行裁剪?
我把代码贴在这里, 首先将捕获的图像保存到本地目录,然后 从目录中取出它并裁剪。我需要捕获图像并立即裁剪它,然后保存。 是否可以将捕获的图像保存在Bundle/Intent Extra中,然后调用裁剪功能Android 是否可以拍照(不保存到外部或内部存储器)并进行裁剪?,android,android-intent,android-camera,android-bundle,Android,Android Intent,Android Camera,Android Bundle,我把代码贴在这里, 首先将捕获的图像保存到本地目录,然后 从目录中取出它并裁剪。我需要捕获图像并立即裁剪它,然后保存。 是否可以将捕获的图像保存在Bundle/Intent Extra中,然后调用裁剪功能 camera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent in
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "img.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, 1);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1){
File file = new File(Environment.getExternalStorageDirectory()+File.separator + "img.jpg");
try {
cropCapturedImage(Uri.fromFile(file));
}
catch(ActivityNotFoundException aNFE){
String errorMessage = "Sorry - your device doesn't support the crop action!";
Toast toast = Toast.makeText(getContext(), errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
if(requestCode==2){
Bundle extras = data.getExtras();
Bitmap thePic = extras.getParcelable("data");
proofImage.setImageBitmap(thePic);
}
}
public void cropCapturedImage(Uri picUri){
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, 2);
}
您可以采用以下两种方式:
您可以使用.bitmapTransform(new circlettransform(this))在圆中进行造型。这里的CircletTransform是一个类,它将拾取的图像塑造成一个圆。您可以通过以下两种方式进行操作:
您可以使用.bitmapTransform(new circlettransform(this))在圆中进行造型。这里的圆变换是一个将拾取的图像塑造成圆形的类。。有很多。请用一个。我不需要裁剪库。我想裁剪一幅图像而不保存它,我想在裁剪后保存它。“我不需要裁剪库”——如果你想裁剪图像,你需要一个裁剪库,或者编写你自己的裁剪库。大约有20亿台安卓设备,跨越数千种设备型号。没有人需要支持
com.android.camera.action.CROP
,也没有人需要支持从内存中裁剪图像的方法。实际上,我的问题不是裁剪图像,在将图像传递到裁剪库或代码之前,我不需要保存该图像。有什么方法可以做到这一点吗?“有什么方法可以做到这一点吗?”--自己使用摄像头API。或者,实现一个ContentProvider
,尝试将整个照片保存在内存中,并使用一个content
方案Uri
指向具有额外输出的提供者。然而,并不是所有的相机应用程序都支持内容Uri
值(尽管它们应该支持),我希望你在试图抓拍照片时会耗尽很多内存。。有很多。请用一个。我不需要裁剪库。我想裁剪一幅图像而不保存它,我想在裁剪后保存它。“我不需要裁剪库”——如果你想裁剪图像,你需要一个裁剪库,或者编写你自己的裁剪库。大约有20亿台安卓设备,跨越数千种设备型号。没有人需要支持com.android.camera.action.CROP
,也没有人需要支持从内存中裁剪图像的方法。实际上,我的问题不是裁剪图像,在将图像传递到裁剪库或代码之前,我不需要保存该图像。有什么方法可以做到这一点吗?“有什么方法可以做到这一点吗?”--自己使用摄像头API。或者,实现一个ContentProvider
,尝试将整个照片保存在内存中,并使用一个content
方案Uri
指向具有额外输出的提供者。然而,并不是所有的相机应用程序都支持内容
Uri
值(尽管它们应该支持),我希望你在试图抓拍照片时会耗尽很多内存。