简体   繁体   English

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

[英]Problems saving and retrieving images

Ok i'm completely editing this post... I have made it so that I can save the file path to my data base. 好的,我正在完全编辑这篇文章...我已经做到了,以便可以将文件路径保存到数据库中。 this works and is saved as /storage/emulated/0/1508blah blah.jpg . 这有效,并保存为/ storage / emulated / 0 / 1508blah blah.jpg。 Now i cannot get my code to read this item back into a picture. 现在我无法获取将此项目读回到图片中的代码。

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

am I missing something here? 我在这里想念什么吗? cause the Toast Is reading the recipe.image just fine and is displaying the path. 因为烤面包正在读取配方。图像很好并且正在显示路径。 why Is the rest not displaying the image? 为什么其余的都不显示图像?

Storage Code 储存码

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

Adding in the files paths seem to be the best solution to the problem i am having so that you @ModularSynth for your help with this. 在文件路径中添加似乎是我遇到的问题的最佳解决方案,以便您@ModularSynth对此提供帮助。 Always making sure all the info is your code to make the file paths work helps. 始终确保所有信息都是您的代码,可以使文件路径正常工作。

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

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