0

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);
}
Koumintang
  • 13
  • 8
  • 1
    Using BLOBs is an **anti-pattern**. Do yourself (and your users) a favour: save the file paths or URLs only. – Phantômaxx Oct 15 '17 at 19:49
  • What do you mean , can you provide an example or direct me to a link with an example of this. cause Ive done really good with this app thus far, but these images seem to be kicking my butt. – Koumintang Oct 15 '17 at 19:53
  • Paths and URLS are strings. Plain strings. There's not a lot to discuss about. – Phantômaxx Oct 15 '17 at 19:54
  • I am aware they are strings, I'm not sure how i would go about saving and retrieving the image file this way. – Koumintang Oct 15 '17 at 19:56
  • everything i have done on this app so far has been self contained or user input – Koumintang Oct 15 '17 at 19:57
  • @Koumintang, [here's an example](https://stackoverflow.com/questions/46518604/how-to-retrieve-a-large-blob-from-database-in-android/46519680#46519680) – MikeT Oct 15 '17 at 20:30
  • @MikeT Thank you, I'll take a look at it. – Koumintang Oct 15 '17 at 20:33
  • @Koumintang to save as BLOB use something along the lines of `values.put(Recipe.KEY_IMAGE, recipe.image)` where recipe.image is a `byte[]` and retrieve using `getBlob()`. Note I beleive there's a 2Mb limit for a cursor. – MikeT Oct 15 '17 at 20:37
  • If you store a path, then you reload the image from the file system. What's difficult in this? – Phantômaxx Oct 15 '17 at 21:14
  • ok So i found out it isnt writing the whole file path for some reason... it stops at the /storage/emulated/0/(filename) when the file is actually saving to /storage/emulated/0/DCIM/Camera/(different file name). if my code is telling it where to store why would it store it elsewhere and with a different file name? I have even tried overriding the save location by typing my own in there but no change to where it saves. – Koumintang Oct 16 '17 at 05:18
  • I believe i found the culprit as to why it wont create the file/directory... I've got a warning on the destination.createNewFile. saying it s being ignored... I've not found a sure fire way to fix this... and Ideas would be great... I have no idea what would even cause it to be ignored.... I have the permissions done in the manifest. – Koumintang Oct 18 '17 at 05:11
  • even if i try to do a mkdir call, those get ignored as well... i'm confused would it be doing this? – Koumintang Oct 18 '17 at 05:25

1 Answers1

0

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.

Koumintang
  • 13
  • 8