存储在SD卡SQLite数据库通过摄像头后,点击保存图片 [英] Save Image after clicking by camera in sqlite database stored in sdcard

查看:157
本文介绍了存储在SD卡SQLite数据库通过摄像头后,点击保存图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的手机摄像头点击图片并保存在SQLite数据库这个图像存储在sdcard.plz告诉我,我该怎么做?下面是code我已经写
对于点击图片

 意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
        档案文件=新的文件(Environment.getExternalStorageDirectory(),BB);        outputFileUri = Uri.fromFile(文件);
        intent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri);
        startActivityForResult(意向,TAKE_PICTURE);


解决方案

给予许可清单中:

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
<使用许可权的android:NAME =android.permission.CAMERA/>
<使用特征的android:NAME =android.hardware.camera/>
<使用特征的android:NAME =android.hardware.camera.autofocus/>文件目的地=新的文件(Environment.getExternalStorageDirectory(),image.jpg文件);
 意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
 intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(目标));
 startActivityForResult(意向,CAMERA_PICTURE);

然后覆盖从目标图像的onActivityResult水道图像文件转换成位图,并保存。
然后将其转换成字节数组

  @覆盖
      公共无效的onActivityResult(INT申请code,INT结果code,意图数据){
        如果(要求code == CAMERA_PICTURE&放大器;&安培;结果code == Activity.RESULT_OK){
               realImageStr =新的String();
             尝试{
        在的FileInputStream =新的FileInputStream(目标);
            BitmapFactory.Options选项=新BitmapFactory.Options();
            options.inSampleSize = 10; // 10倍缩减像素采样
            Log.d(PP,位图工厂==========+期权);
            位图user_picture_bmp = BitmapFactory.de codeStream(中,空,期权);
            ByteArrayOutputStream BOS =新ByteArrayOutputStream();
            user_picture_bmp.com preSS(Bitmap.Com pressFormat.PNG,100,BOS);
            字节[] = bArray bos.toByteArray();
        }赶上(例外五)
        {
        }}}

当你将节省成字节类型,然后在保存到数据库乌尔字节code图像coloumn和图像列数据类型的 BLOB类型即可。

I want to click image from camera of my phone and then save this image in sqlite Database which is stored in sdcard.plz tell me How I can do this??following is the code I have written for clicking Image

        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);

解决方案

Give Permission in manifest:

<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);

then override onActivityResult gat image file from destination image it convert into bitmap and save this. then convert it into byte array

 @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) 
        {
        } }}

When you will save into byte type then save in to database ur byteCode in image coloumn and image column data type is BLOB type.

这篇关于存储在SD卡SQLite数据库通过摄像头后,点击保存图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆