daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String path = Environment.getExternalStorageDirectory().toString();
  2. OutputStream fOut = null;
  3. file = new File(path, "image.jpg");
  4. fOut = new FileOutputStream(file);
  5. Bitmap bitmap = BitmapFactory.decodeResource (getResources(), R.drawable.xyz);
  6. bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
  7. fOut.flush();
  8. fOut.close();
  9. MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
  10.    
  11. String root = Environment.getExternalStorageDirectory().toString();
  12.   File myDir = new File(root + "/saved_images");    
  13.   myDir.mkdirs();
  14.   Random generator = new Random();
  15.   int n = 10000;
  16.   n = generator.nextInt(n);
  17.   String fname = "Image-"+ n +".jpg";
  18.   File file = new File (myDir, fname);
  19.   if (file.exists ()) file.delete ();
  20.   try {
  21.        FileOutputStream out = new FileOutputStream(file);
  22.        finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
  23.        out.flush();
  24.        out.close();
  25.  
  26. } catch (Exception e) {
  27.        e.printStackTrace();
  28. }
  29.    
  30. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top