Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想将图像存储在sqlite数据库中,该数据库取自gallery和camera android_Android_Imageview_Android Sqlite_Image Gallery - Fatal编程技术网

我想将图像存储在sqlite数据库中,该数据库取自gallery和camera android

我想将图像存储在sqlite数据库中,该数据库取自gallery和camera android,android,imageview,android-sqlite,image-gallery,Android,Imageview,Android Sqlite,Image Gallery,我有一个应用程序,用户可以通过单击Imageview并设置图像以及从相机拍摄新照片来添加图像。我想将该设置图像存储到sqlite数据库中。 **AddkeyEventdetail.java** package com.example.kidsfinal; import java.util.Calendar; import android.app.DatePickerDialog; import android.app.Dialog; import a

我有一个应用程序,用户可以通过单击Imageview并设置图像以及从相机拍摄新照片来添加图像。我想将该设置图像存储到sqlite数据库中。

**AddkeyEventdetail.java**



  package com.example.kidsfinal;

    import java.util.Calendar;

    import android.app.DatePickerDialog;
    import android.app.Dialog;
    import android.content.Intent;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.support.v4.app.DialogFragment;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.ImageView;
    import android.widget.Spinner;
    import android.widget.TextView;

    import com.example.slidingmenuexample.R;

    public class AddChildHoodEventActivity extends SmartActivity {

        ImageView ivChildPics;
        EditText edtEventDate, edtEventDetails;
        Button btnEventDetailSubmit, btnopenCamera;
        Spinner spinnerSelectChild;
        Bitmap bmp;

        Calendar calendar = Calendar.getInstance();
        int mDay = calendar.get(Calendar.DAY_OF_MONTH), mMonth = calendar
                .get(Calendar.MONTH), mYear = calendar.get(Calendar.YEAR) - 1;

        @Override
        public void onCreate(Bundle arg0) {
            // TODO Auto-generated method stub
            super.onCreate(arg0);
            setContentView(R.layout.addchildhoodevents);
            createDrawer();
            initComponent();
            prepareView();
            setOnListener();
        }

        private void initComponent() {
            // TODO Auto-generated method stub
            ivChildPics = (ImageView) findViewById(R.id.kids_addkeyevent_imageview_childpics);
            edtEventDate = (EditText) findViewById(R.id.kids_addkeyevent_edt_addkeyevent);
            edtEventDetails = (EditText) findViewById(R.id.kids_addkeyevent_edt_eventdetails);
            btnEventDetailSubmit = (Button) findViewById(R.id.kids_addkeyevent_btn_submit);
            btnopenCamera = (Button) findViewById(R.id.kids_addkeyevent_btn_opencamera);
        }

        private void prepareView() {

        }

        private void setOnListener() {

            ivChildPics.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    openGallery();

                }

                private void openGallery() {
                    Intent opengallery = new Intent(Intent.ACTION_GET_CONTENT);
                    opengallery.setType("Image/");
                    startActivityForResult(opengallery, 1);
                }
            });

            btnopenCamera.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    OpenCamera();
                }

                private void OpenCamera() {
                    Intent openCam = new Intent(
                            "android.media.action.IMAGE_CAPTURE");
                    startActivityForResult(openCam, 0);

                }
            });



        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == 0 && resultCode == RESULT_OK) {
                if (data != null) {

                    bmp = (Bitmap) data.getExtras().get("data");

                    ivChildPics.setImageBitmap(bmp); /*
                                                     * this is image view where you
                                                     * want to set image
                                                     */

                    Log.d("camera ---- > ", "" + data.getExtras().get("data"));

                }
            }

            else {
                Uri selectedImage = data.getData();

                String[] filePathColumn = { MediaStore.Images.Media.DATA };
                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();

                if (bmp != null && !bmp.isRecycled()) {
                    bmp = null;
                }

                bmp = BitmapFactory.decodeFile(filePath);
                ivChildPics.setBackgroundResource(0);
                ivChildPics.setImageBitmap(bmp);
            }

        }

    }
database.java

public void insertAddKeyEvent(字节[]childpic,字符串eventDate,字符串eventDetails)


通过以下方式将
位图
转换为
字节[]

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, baos);
byte[] imageData = baos.toByteArray();

并添加
字节[]
进入数据库中的
BLOB
字段。

在SQLite中将图像设置为BLOB,或者只是链接到存储中的img?我正在寻找代码bro我搜索了代码bt没有得到它,所以请你给我提些建议。我已经为数据库以及打开相机和画廊做了编码。我已经共享了我的编码,所以请确实建议我.After
ivChildPics.setImageBitmap(bmp)
对于gallery,我应该做同样的事情吗?是的,如果您可以在
图像视图中看到图像,图像将以何种形式存储在数据库中?它是图像路径吗?否,它将存储为
BLOB
如果要检索它,您必须在
byte[]中获取它。
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, baos);
byte[] imageData = baos.toByteArray();