I am trying to get an array of bytes of an image stored locally on the phone. I am using the code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upload);
startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Cursor Cur = Upload.this.managedQuery(selectedImage, null, null, null,null);
if (Cur.moveToFirst()) {
File Img = new File(selectedImage.getPath());
long Length = Cur.getLong(Cur.getColumnIndex(ImageColumns.SIZE));
byte[] B = new byte[(int)Length-1];
FileInputStream ImgIs;
try {
ImgIs = new FileInputStream(Img);
ImgIs.read(B);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
int i = B.length;
}
}
}
But he throws FileNotFound exceptionon
ImgIs = new FileInputStream(Img)
How can i get bytes?
source
share