I'm trying to load an screenshot from my Environment.getExternalStorageDirectory() and try to convert it to bitmap
public void onPictureTaken(String path) throws IOException {
String photoPath = filepath + "/" + path;; //UPDATE WITH YOUR OWN JPG FILE
File directory = new File (filepath);
File file = new File(directory, path);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(photoPath, options);
// Calculate inSampleSize
options.inSampleSize = 4;
options.inJustDecodeBounds = false;
BitmapFactory.decodeFile(photoPath, options);
}
--- SkImageDecoder::Factory returned null
Here is my function which calls onPictureTaken:
private void observeSceenshot(){
filepath = Environment.getExternalStorageDirectory()
+ File.separator + Environment.DIRECTORY_PICTURES
+ File.separator + "Screenshots";
Log.d(TAG, filepath);
FileObserver fileObserver = new FileObserver(filepath, FileObserver.CREATE) {
@Override
public void onEvent(int event, String path) {
Log.d(TAG, event + " " + path);
try {
onPictureTaken(path);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
fileObserver.startWatching();
}
Does anybody know how to solve the problem? Maybe because my png is to big(1280x720)? I also tried this solution with the same result: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Edit: Here is the log
03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/DBG_com.example.chilred_pc.myapplication.ObserveScreenshots: 256 Screenshot_2016-03-02-11-56-19.png 03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/directory: /storage/emulated/0/Pictures/Screenshots 03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/file: /storage/emulated/0/Pictures/Screenshots/Screenshot_2016-03-01-16-38-08.png 03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/fileSize: 35061 03-02 11:56:19.807 11581-11716/com.example.chilred_pc.myapplication D/skia: --- SkImageDecoder::Factory returned null 03-02 11:56:19.808 11581-11716/com.example.chilred_pc.myapplication D/skia: --- decoder->decode returned false
int fileSize = file.length()
? what is the value of fileSize – Trutko