Its important to createnewfile(), because it creates the file. also it is important that during testing, the sdcard is unmount, there will be an exception about the parent directory being unreachable.
This can be potentially useful:
http://stackoverflow.com/questions/1431042/problem-in-creating-temporary-file-in-android
File photo = new File(Environment.getExternalStorageDirectory(),"modcloth/placeholder.jpg");
try {
photo.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(photo.getPath());
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 5; // sets image quality
Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length,options);
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment