Pepper机器人QISDK拍照存JPG遇只读文件系统问题求解决方案
Hey there, I’ve run into this exact permission issue with Pepper before—its system locks down most directories for security, so your initial code was trying to write to a restricted area. Let’s break down two solid solutions, especially since you don’t need the Bitmap at all:
1. Use Your App’s Private Writable Directory
Pepper runs on Android, so every app gets its own private directory that’s guaranteed writable. Instead of creating files in the root or current working directory, use getFilesDir() (from your app context) to get this safe path:
// Get your app's private writable directory File appFilesDir = getContext().getFilesDir(); File jpgFile = new File(appFilesDir, "photo.jpg"); try { FileOutputStream outStream = new FileOutputStream(jpgFile); getPicture().compress(Bitmap.CompressFormat.JPEG, 90, outStream); // Adjust quality as needed Log.i("PHOTO_SAVE", "Successfully saved JPG to: " + jpgFile.getAbsolutePath()); outStream.close(); } catch (IOException e) { Log.e("PHOTO_SAVE", "Failed to save JPG", e); }
This bypasses the read-only restriction because you’re writing to an area your app owns.
2. Skip Bitmap Entirely: Let QISDK Generate JPG Directly
Since you don’t need the Bitmap, this is the better approach—cut out the middleman and have the TakePicture action save a JPG directly to your writable directory. Use the TakePictureBuilder to configure output format and path:
// Create the output file in your app's private directory File outputJpg = new File(getContext().getFilesDir(), "direct_photo.jpg"); // Build and execute the TakePicture action with JPG output TakePicture takePictureAction = TakePictureBuilder.with(qiContext) .withOutputFormat(ImageFormat.JPEG) // Specify JPG format .withOutputFile(outputJpg) // Tell the SDK where to save it .build(); // Run the action asynchronously takePictureAction.async().andThenConsume(result -> { if (result.getStatus() == TakePictureStatus.SUCCESS) { Log.i("DIRECT_PHOTO", "JPG saved directly! Path: " + outputJpg.getAbsolutePath()); } else { Log.e("DIRECT_PHOTO", "Failed to capture photo: " + result.getStatus()); } }).get();
This method is more efficient (no Bitmap in memory) and avoids any manual compression steps—QISDK handles all the heavy lifting for you.
Quick Notes
- Avoid using external storage on Pepper unless absolutely necessary; its internal app directories are more reliable for this use case.
- Adjust the JPEG quality (the
90in the first example) to balance file size and image clarity as needed.
内容的提问来源于stack exchange,提问作者Максим Чижиков

