感谢您提前感谢。
我在下一个节目中编码
a. use internal camera app(I use Intent and other app to take pickture).
b. get image without saving into file.
在我的应用中,用户可以选择信用卡并发送到服务器。不需要信用卡图像文件,将图像保存到文件中不利于安全。
有可能吗?
如果不可能,还有别的吗?
一个。打开jpg文件,将所有像素编辑成黑色
湾使用https://github.com/Morxander/ZeroFill
Whitch方法是可以实现的吗?
答案 0 :(得分:1)
简短回答是NO
如果不将照片保存到图像中,则无法从默认相机应用中获取照片
您可以使用Camera API在您的应用中拍照,而不是使用第三方默认系统照片应用。
答案 1 :(得分:1)
在这里查看完整Source.
在import xml.etree.ElementTree as etree
:
AndroidManifest.xml
在<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
上,首先定义:
Activity
然后在static final int REQUEST_IMAGE_CAPTURE = 1;
private Bitmap mImageBitmap;
private String mCurrentPhotoPath;
private ImageView mImageView;
:
Intent
onClick
添加以下支持方法:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
Log.i(TAG, "IOException");
}
// Continue only if the File was successfully created
if (photoFile != null) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}
}
然后收到结果:
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, // prefix
".jpg", // suffix
storageDir // directory
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
使其有效的是@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
try {
mImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath));
mImageView.setImageBitmap(mImageBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
,它与developer.android.com的代码不同。原始代码给了我一个MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath))
。