简体   繁体   中英

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 . 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. Always making sure all the info is your code to make the file paths work helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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