【发布时间】:2017-10-15 19:45:51
【问题描述】:
好的,我正在完全编辑这篇文章...我已经做到了,以便我可以将文件路径保存到我的数据库中。这有效并保存为 /storage/emulated/0/1508blah blah.jpg 。现在我无法让我的代码将这个项目读回图片中。
imagePhoto = (ImageView)findViewById(R.id.detail_recipe_image);
Toast.makeText(this, recipe.image, Toast.LENGTH_SHORT).show();
Bitmap bmp = BitmapFactory.decodeFile(String.valueOf(recipe.image));
imagePhoto.setImageBitmap(bmp);
我在这里遗漏了什么吗?导致 Toast 正在读取 recipe.image 并显示路径。为什么其余的不显示图像?
存储代码
private void onCaptureImageResult(Intent data) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
String picturePath = destination.toString();
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
textImagePath.setText(picturePath.toString());
ImageView img = (ImageView)findViewById(R.id.addphotoview);
img.setImageBitmap(thumbnail);
}
【问题讨论】:
-
使用 BLOB 是一种反模式。帮自己(和您的用户)一个忙:只保存文件路径或 URL。
-
你是什么意思,你能提供一个例子或指导我到一个链接与这个例子。因为到目前为止,我在这款应用上做得非常好,但这些图片似乎让我大吃一惊。
-
路径和 URLS 是字符串。纯字符串。没什么好讨论的。
-
我知道它们是字符串,我不确定如何以这种方式保存和检索图像文件。
-
到目前为止我在这个应用上所做的一切都是独立的或用户输入的
标签: android arrays database image android-sqlite