Ok so I am supposed to make an android application but for some reason, I cannot convert my picture to a bitmap image. It's a .png image and when I try to convert it in my code, my application just crashes, no errorcode or nothing. Ive tried fixing it a ton of times, but I'm just not that good in programming and I need help, it just won't work.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FOTO_NEMEN && resultCode == RESULT_OK)
{
final File file = temp;
try {
String urienzo = "file:///sdcard/DCIM/2013-01-30_13-27-28.png";
Uri uri = Uri.parse(urienzo);
Bitmap foto = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
if (foto == null) {
Toast.makeText(this, Uri.fromFile(file).toString(), Toast.LENGTH_SHORT).show();
return;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
foto.compress(Bitmap.CompressFormat.PNG, 0 , bos);
final byte[] bytes = bos.toByteArray();
bos.close();
AsyncTask<Void,Void,Void> taak = new AsyncTask<Void,Void,Void>() {
@Override
protected Void doInBackground(Void... params) {
stuurAfbeelding(bytes);
return null;
}
};
taak.execute(null,null);
} catch (IOException e) {
Log.e("Snapper","Fout bij foto nemen: " + e);
}
}
}
Whenever I get to the bitmap foto part, it crashes my application without any error message. The reason my URI is hardcoded is because I think the URI.fromfile was giving me the wrong URI, so I wanted to be sure. Now it just crashes and I have no idea what is wrong with my code. Could someone aid me?