繁体   English   中英

保存和检索图像时出现问题

[英]Problems saving and retrieving images

好的,我正在完全编辑这篇文章...我已经做到了,以便可以将文件路径保存到数据库中。 这有效,并保存为/ 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);

我在这里想念什么吗? 因为烤面包正在读取配方。图像很好并且正在显示路径。 为什么其余的都不显示图像?

储存码

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);
}

在文件路径中添加似乎是我遇到的问题的最佳解决方案,以便您@ModularSynth对此提供帮助。 始终确保所有信息都是您的代码,可以使文件路径正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM