che*_*mar 8 sqlite android sqliteopenhelper android-sqlite android-database
我是开发新手,通过将图像转换为字节数组并将其存储到 BLOB 中的 SQLite 数据库(在下面的代码中找到),我成功地将图像存储到数据库中。但是我不知道如何将音频/视频存储到数据库中,任何人都可以帮助我 PLZ ...
public void getImage(View view){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/* video/*");
startActivityForResult(Intent.createChooser(intent, "select picture"), 1);
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(resultCode == RESULT_OK){
Uri imageUri = data.getData();
String imagePath = getPath(imageUri);
image1.setVisibility(View.VISIBLE);
image1.setImageURI(imageUri);
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
Toast.makeText(getApplicationContext(), ""+bitmap, Toast.LENGTH_SHORT).show();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
img = byteArrayOutputStream.toByteArray();
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public void saveImage(View v){
imageDatabase = new ImageDatabase(this);
imageDatabase.insert("first",img);
Toast.makeText(getApplicationContext(), ""+imageDatabase.numberOfRows(),Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我从 sdcard 中获取图像并在 ImageView 中显示并存储到数据库中。
归档时间: |
|
查看次数: |
11206 次 |
最近记录: |