asthasharma017
Lurker
Hello,
I am writing a code for an android app in which I have to captures image and save it into internal storage of android. For this I have written the following code-
This code creates jpeg file but don't write the image into it.
Later I tried writing following code in onActivityResult-
But its still not working. Please help...
I am writing a code for an android app in which I have to captures image and save it into internal storage of android. For this I have written the following code-
Code:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
String newPath = PATH+"/"+folderName+"/"+imageName+".jpg";
File file = new File( newPath );
file.mkdirs();
Uri outputFileUri = Uri.fromFile( file );
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, 0);
Later I tried writing following code in onActivityResult-
Code:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
byte[] bitmapdata = bos.toByteArray();
File file = new File( newPath );
FileOutputStream fos = new FileOutputStream(file);
fos.write(bitmapdata);
}