Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String path = Environment.getExternalStorageDirectory().toString();
- OutputStream fOut = null;
- file = new File(path, "image.jpg");
- fOut = new FileOutputStream(file);
- Bitmap bitmap = BitmapFactory.decodeResource (getResources(), R.drawable.xyz);
- bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
- fOut.flush();
- fOut.close();
- MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
- String root = Environment.getExternalStorageDirectory().toString();
- File myDir = new File(root + "/saved_images");
- myDir.mkdirs();
- Random generator = new Random();
- int n = 10000;
- n = generator.nextInt(n);
- String fname = "Image-"+ n +".jpg";
- File file = new File (myDir, fname);
- if (file.exists ()) file.delete ();
- try {
- FileOutputStream out = new FileOutputStream(file);
- finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
- out.flush();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Add Comment
Please, Sign In to add comment