我想从手机的相机中点击图像,然后将此图像保存在存储在sdcard.plz中的sqlite数据库中告诉我如何才能执行此操作?以下是我编写的代码 单击图像
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), bb);
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
答案 0 :(得分:1)
在清单中提供权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
File destination = new File(Environment.getExternalStorageDirectory(),"image.jpg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
startActivityForResult(intent, CAMERA_PICTURE);
然后从目标图像覆盖onActivityResult gat图像文件,将其转换为位图并保存。 然后将其转换为字节数组
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode == CAMERA_PICTURE && resultCode == Activity.RESULT_OK) {
realImageStr = new String("");
try {
FileInputStream in = new FileInputStream(destination);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 10; //Downsample 10x
Log.d("PP", " bitmap factory=========="+options);
Bitmap user_picture_bmp = BitmapFactory.decodeStream(in, null, options);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
user_picture_bmp.compress(Bitmap.CompressFormat.PNG, 100, bos);
byte[] bArray = bos.toByteArray();
} catch (Exception e)
{
} }}
当你保存到字节类型然后保存到数据库ur字形colode中的byteCode和图像列数据类型是 BLOB类型。