Android Studio使用ImagePath将图像保存并检索到sqlite数据库

Android Studio使用ImagePath将图像保存并检索到sqlite数据库,android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,在我的应用程序中,我必须用sqlite数据库的路径保存图像,因为当我将其保存为BLOB时,sqlite会给出一个错误。这个错误是一个游标窗口。 根据研究,SQLite不支持一行超过2MB的数据。所以,我不得不改变方法 数据库表 图像将保存在“questPhoto”中 索鲁帕拉斯级 我添加到图像数据库的类 我用来将信息保存到数据库的方法。 和onActivityResult private void GalleryOpen() { GalIntent=new Intent(Intent.A

在我的应用程序中,我必须用sqlite数据库的路径保存图像,因为当我将其保存为BLOB时,sqlite会给出一个错误。这个错误是一个游标窗口。 根据研究,SQLite不支持一行超过2MB的数据。所以,我不得不改变方法

数据库表

图像将保存在“questPhoto”中

索鲁帕拉斯级

我添加到图像数据库的类

我用来将信息保存到数据库的方法。 和onActivityResult

private void GalleryOpen() {
    GalIntent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(Intent.createChooser(GalIntent,"Select Image from Gallery"),2);
}

private void CameraOpen() {
    CamIntent =new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file=new File(Environment.getExternalStorageDirectory(),"file"+String.valueOf(System.currentTimeMillis())+".jpg");
    uri=Uri.fromFile(file);
    CamIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
    CamIntent.putExtra("return-data",true);
    startActivityForResult(CamIntent,0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == 0 && resultCode == RESULT_OK)  // Open Camera
        CropImage();
    else if(requestCode == 2){    // Open Gallery
        if(data!= null){
            uri=data.getData();
            CropImage();
        }
    }
    else if(requestCode == 1){
        if(data !=null){
            Bundle bundle=data.getExtras();
            Bitmap bitmap= (Bitmap) bundle.get("data");

            Picasso.with(sorupaylas.this)
                    .load(uri)
                    .resize(1100,1100)
                    .centerCrop()
                    .into(imageView);
            imageView.setImageBitmap(bitmap);
        }
    }
}
我得到了这个代码行的图像。
我将等待您的建议。

堆栈溢出用于编程问题。您的问题是什么?如何使用ImagePath将图像保存和检索到数据库?将位图写入文件。在数据库中保存有关您将其保存到哪个文件的信息。您能给我看一个示例代码行或链接吗?
ContentValues cv=new ContentValues();
    cv.put("questTime",getDateTime().toString());
    cv.put("stuId",id_degeri);
    cv.put("lesson",txtdegiskenkontrol.getText().toString());
    cv.put("subject",konusec.getText().toString());
    cv.put("answer",textdogrucevap.getText().toString());
    cv.put("point",textsorupuan.getText().toString());
    cv.put("questPhoto",imageViewToByte(imageView));
    long id = mSQLiteDb.insert("questions",null,cv);
    Toast.makeText(sorupaylas.this, String.valueOf(id), Toast.LENGTH_SHORT).show();

private byte[] imageViewToByte(ImageView imageView) {
    Bitmap bitmap=((BitmapDrawable)imageView.getDrawable()).getBitmap();
    ByteArrayOutputStream stream= new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG,100,stream);
    byte[] byteArray =stream.toByteArray();
    return byteArray;
}
private void GalleryOpen() {
    GalIntent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(Intent.createChooser(GalIntent,"Select Image from Gallery"),2);
}

private void CameraOpen() {
    CamIntent =new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file=new File(Environment.getExternalStorageDirectory(),"file"+String.valueOf(System.currentTimeMillis())+".jpg");
    uri=Uri.fromFile(file);
    CamIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
    CamIntent.putExtra("return-data",true);
    startActivityForResult(CamIntent,0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == 0 && resultCode == RESULT_OK)  // Open Camera
        CropImage();
    else if(requestCode == 2){    // Open Gallery
        if(data!= null){
            uri=data.getData();
            CropImage();
        }
    }
    else if(requestCode == 1){
        if(data !=null){
            Bundle bundle=data.getExtras();
            Bitmap bitmap= (Bitmap) bundle.get("data");

            Picasso.with(sorupaylas.this)
                    .load(uri)
                    .resize(1100,1100)
                    .centerCrop()
                    .into(imageView);
            imageView.setImageBitmap(bitmap);
        }
    }
}
byte[] getphotoOfQuest=cursor.getBlob(cursor.getColumnIndexOrThrow("questPhoto"));
                bitmap=BitmapFactory.decodeByteArray(getphotoOfQuest,0,getphotoOfQuest.length);