0
好的,我完全编辑这篇文章......我已经做到了,以便我可以将文件路径保存到我的数据库。这工作,并保存为/ 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);
我在这里错过了什么?导致吐司正在阅读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);
}
使用BLOBs是**反模式**。为自己(和你的用户)做一个好处:只保存文件路径或URL。 –
你是什么意思,你可以提供一个例子,或者直接给我一个链接的例子。因为迄今为止我已经完成了这个应用程序,但是这些图像似乎在踢我的屁股。 – Koumintang
路径和URL是字符串。纯字符串。没有什么需要讨论的。 –