Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.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
Android:如何将字节数组传递给blob(将相机图像存储到sqlite中)_Android_Android Sqlite - Fatal编程技术网

Android:如何将字节数组传递给blob(将相机图像存储到sqlite中)

Android:如何将字节数组传递给blob(将相机图像存储到sqlite中),android,android-sqlite,Android,Android Sqlite,如何正确更改此byte[]photo=getBytes(imageBitmap)要存储在数据库Blob中吗 if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data");

如何正确更改此
byte[]photo=getBytes(imageBitmap)要存储在数据库Blob中吗

if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            //ImageView imageview = findViewById(R.id.imageView);
            //imageview.setImageBitmap(imageBitmap);

            //Bitmap to bytes for database
            byte[] photo = getBytes(imageBitmap);

            Bitmap bmp = BitmapFactory.decodeByteArray(photo, 0, photo.length);
            ImageView image = (ImageView) findViewById(R.id.imageView);

            image.setImageBitmap(Bitmap.createScaledBitmap(bmp, image.getWidth(), image.getHeight(), false));


           // DatabaseHandler mydb = new DatabaseHandler(getApplicationContext());
           // Walk walk = new Walk(photo);
          //  mydb.addWalk(walk);
}

您是否尝试过使用ByteArrayOutputStream? 你可以查看文档

或者为了让事情变得简单你可以像这家伙那样做

`


`首先,确切的问题是什么?保存图像还是将其存储到数据库中

创建表t1(id整数主键,数据BLOB)

归结起来:

InputStream is = context.getResources().open(R.drawable.MyImageFile);
try {
    byte[] buffer = new byte[CHUNK_SIZE];
    int size = CHUNK_SIZE;
    while(size == CHUNK_SIZE) {
        size = is.read(buffer);  //read chunks from file
        if (size == -1) break;

        ContentValues cv = new ContentValues();
        cv.put(CHUNK, buffer);       //CHUNK blob type field of your table

        long rawId = database.insert(TABLE, null, cv); //TABLE table name
    }
} catch (Exception e) {
    Log.e(TAG, "Error saving raw image to: "+rawId, e);
}

存储在数据库中存储原始字节?创建表t1(id整数主键,数据BLOB);你试过这个方法吗?看起来像是一个类似的问题,你应该接受适合你的答案。。。或者告诉人们他们不工作:)
InputStream is = context.getResources().open(R.drawable.MyImageFile);
try {
    byte[] buffer = new byte[CHUNK_SIZE];
    int size = CHUNK_SIZE;
    while(size == CHUNK_SIZE) {
        size = is.read(buffer);  //read chunks from file
        if (size == -1) break;

        ContentValues cv = new ContentValues();
        cv.put(CHUNK, buffer);       //CHUNK blob type field of your table

        long rawId = database.insert(TABLE, null, cv); //TABLE table name
    }
} catch (Exception e) {
    Log.e(TAG, "Error saving raw image to: "+rawId, e);
}