Last active
April 9, 2018 16:51
-
-
Save alitamoor65/5babe053eaf4be507a333d8e747fe757 to your computer and use it in GitHub Desktop.
Get Screen Shot and Save to Local Sorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saveButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
AdRequest adRequest = new AdRequest.Builder().build(); | |
utils.interstitialAd.loadAd(adRequest); | |
View content = findViewById(R.id.combineImageID); | |
Bitmap bitmap = getScreenShoot(content); | |
String currentImage = "Pakistan-Independence-Frame-" + System.currentTimeMillis() + ".png"; | |
Toast.makeText(MainActivity.this, "Saved To: " + currentImage, Toast.LENGTH_SHORT).show(); | |
String proSavedPath = storeImage(bitmap,currentImage); | |
//Open Gallery | |
Intent intent=new Intent(MainActivity.this, ViewActivity.class); | |
Bundle bundle = new Bundle(); | |
bundle.putString("PRO_PATH",proSavedPath); | |
intent.putExtras(bundle); | |
startActivity(intent); | |
finish(); | |
} | |
}); | |
private Bitmap getScreenShoot(View view){ | |
view.setDrawingCacheEnabled(true); | |
Bitmap bitmap =Bitmap.createBitmap(view.getDrawingCache()); | |
view.setDrawingCacheEnabled(false); | |
return bitmap; | |
} | |
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 To: \n" + file, Toast.LENGTH_SHORT).show(); | |
Log.i("INFO","Profile Saved: " + file); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
String filePath = dirPath + "/" + fileName; | |
return filePath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment