1

我想找到一种方法将 sqlite 数据库中的图像保存在 sdcard 中,如果我使用简单的查询,我可以找到图像数据,但是如何保存它们,例如,sdcard/temp 我搜索了很多,但找不到任何符合我想要的东西

4

1 回答 1

0

我假设您将从数据库中提取 blob 并从那里获取位图或其他任何内容。您可能需要查看http://developer.android.com/reference/java/io/File.html。您可以使用 File 中的方法为给定路径创建文件。

如何将位图编码为 blob 将影响重新序列化这些位图的方式。

来自这篇文章: Android:从数据库中检索位图的问题


编码到数据库:

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.JPEG, THUMB_QUALITY, outputStream);
mByteArray = outputStream.toByteArray();  // write this to database as blob

从数据库重新序列化:

ByteArrayInputStream inputStream = new ByteArrayInputStream(cursor.getBlob(columnIndex));
Bitmap mBitmap = BitmapFactory.decodeStream(inputStream);

保存到文件:

String path = Environment.getExternalStorageDirectory().toString();
File filename = new File(path, "myImg.png");
FileOutputStream out = new FileOutputStream(filename);
bitmapp.compress(Bitmap.CompressFormat.PNG, <<COMPRESSION_AMT>>, out);
out.flush();
out.close();
于 2013-04-02T22:48:32.230 回答