Reputation: 73
We want to take a picture on a Pepper Robot and save it (somehow) -> The first idea is to compress to .jpg file.
TakePicture action is taken from QISDK tutorial, then we create the File as given below:
File file = new File("image.jpg"); try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } try { FileOutputStream out = new FileOutputStream(file); getPicture().compress(Bitmap.CompressFormat.JPEG, 100, out); // getPicture() is The Bitmap we get from TakePicture Action. Log.i("COMPRESSED", "SUCCES"); out.close(); } catch (IOException e) { Log.i("COMPRESSED", "FAIL"); e.printStackTrace(); }
But the code throws exception IOException Read-only file system. That means, that the Robot environment prevents from creating/writing files, which I believe is for the safety reasons. But the picture in Bitmap format is not what we want.
Is there any possible work-around or solutions to this problem?
Upvotes: 0
Views: 197
Reputation: 73
I have found a solution, I just made a file with
file = File.createTempFile("image", ".jpg", this.getCacheDir());
This way it allows to make a fully writable temporary file, that can afterward be compressed, edited etc.
Using absolute path to the /temp android folder might also work, but that depends on Android version.
Upvotes: 0