Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String storeImage(Bitmap bitmap,String fileName){
- String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FilterImages";
- File dir = new File(dirPath);
- if(!dir.exists()){
- dir.mkdir();
- }
- File file = new File(dirPath,fileName);
- try{
- FileOutputStream fileOutputStream = new FileOutputStream(file);
- bitmap.compress(Bitmap.CompressFormat.PNG,100,fileOutputStream);
- fileOutputStream.flush();
- fileOutputStream.close();
- //Toast.makeText(this, "Saved: " + file, Toast.LENGTH_SHORT).show();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- String filePath = dirPath + "/" + fileName;
- return filePath;
- }
- public void copyFileOrDir(String path) {
- AssetManager assetManager = this.getAssets();
- String assets[] = null;
- try {
- assets = assetManager.list(path);
- if (assets.length == 0) {
- copyFile(path);
- } else {
- String fullPath = "data/data/" + this.getPackageName() + "/" + path;
- Log.i("INFO","Copying to : " + fullPath);
- File dir = new File(fullPath);
- if (!dir.exists())
- dir.mkdir();
- for (int i = 0; i < assets.length; ++i) {
- copyFileOrDir(path + "/" + assets[i]);
- }
- }
- } catch (IOException ex) {
- Log.i("INFO", "I/O Exception");
- }
- }
- private void copyFile(String filename) {
- AssetManager assetManager = this.getAssets();
- InputStream in = null;
- OutputStream out = null;
- try {
- in = assetManager.open(filename);
- String newFileName = "/data/data/" + this.getPackageName() + "/" + filename;
- Log.i("INFO","File Name: " + filename);
- out = new FileOutputStream(newFileName);
- byte[] buffer = new byte[1024];
- int read;
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
- }
- in.close();
- in = null;
- out.flush();
- out.close();
- out = null;
- } catch (Exception e) {
- Log.i("INFO", "Catch: " + e.getMessage());
- }
Add Comment
Please, Sign In to add comment