I get an Object containing a File:
public class Ordo implements java.io.Serializable{
static final long serialVersionUID = 11223344;
public String id;
public String name;
public String date;
public String status;
public File thumbnail;
and I need to convert this File into a Bitmap to be viewed on an Activity. I'm doing the following:
thumbnail = list.getFileFromId(vid);
Bitmap pic = null;
try {
byte[] buffer = new byte[8192];
int bytesRead;
FileInputStream input = new FileInputStream(thumbnail);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
while((bytesRead = input.read(buffer)) != -1){
stream.write(buffer, 0, bytesRead);
}
pic = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
} catch (Exception e) {
e.printStackTrace();
}
but I get the following error:
04-28 18:16:16.759: W/System.err(31995): java.io.FileNotFoundException: 1461854326445.png: open failed: ENOENT (No such file or directory) 04-28 18:16:16.779: W/System.err(31995): at libcore.io.IoBridge.open(IoBridge.java:456) 04-28 18:16:16.779: W/System.err(31995): at java.io.FileInputStream.(FileInputStream.java:76) 04-28 18:16:16.779: W/System.err(31995): at com.jre.link.View.onCreate(ViewOrdo.java:83) 04-28 18:16:16.779: W/System.err(31995): at android.app.Activity.performCreate(Activity.java:6550) 04-28 18:16:16.779: W/System.err(31995): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120) 04-28 18:16:16.779: W/System.err(31995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102) 04-28 18:16:16.779: W/System.err(31995): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3248) 04-28 18:16:16.779: W/System.err(31995): at android.app.ActivityThread.access$1000(ActivityThread.java:197) 04-28 18:16:16.779: W/System.err(31995): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681) 04-28 18:16:16.779: W/System.err(31995): at android.os.Handler.dispatchMessage(Handler.java:102) 04-28 18:16:16.779: W/System.err(31995): at android.os.Looper.loop(Looper.java:145) 04-28 18:16:16.779: W/System.err(31995): at android.app.ActivityThread.main(ActivityThread.java:6872) 04-28 18:16:16.779: W/System.err(31995): at java.lang.reflect.Method.invoke(Native Method) 04-28 18:16:16.779: W/System.err(31995): at java.lang.reflect.Method.invoke(Method.java:372) 04-28 18:16:16.779: W/System.err(31995): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 04-28 18:16:16.779: W/System.err(31995): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
it seems that I need to create a physical file from my File Object... any idea how I can solve that ?
Thanks for your answers.
BitmapFactory.decodeFile(thumbnail);
– greenapps