Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. private class Test extends AsyncTask<Void,Void,Void>{
  2.  
  3. @Override
  4. protected Void doInBackground(Void... voids) {
  5.  
  6.  
  7. Bitmap m = loadBitmapFromView(l);
  8.  
  9. replaceColor(m,Color.BLACK, Color.WHITE);
  10.  
  11. ImageView i = findViewById(R.id.bm);
  12. String root = Environment.getExternalStorageDirectory().toString();
  13. File myDir = new File(root + "/req_images");
  14. myDir.mkdirs();
  15. int n = 1;
  16. String fname = "Image-" + n + ".jpg";
  17. File file = new File(myDir, fname);
  18. Log.i(TAG, "" + file);
  19. if (file.exists())
  20. file.delete();
  21. try {
  22. FileOutputStream out = new FileOutputStream(file);
  23. m.compress(Bitmap.CompressFormat.JPEG, 100, out);
  24. out.flush();
  25. out.close();
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. }
  29.  
  30. mFiles.add(file.getPath());
  31.  
  32. return null;
  33. }
  34.  
  35. @Override
  36. protected void onPostExecute(Void aVoid) {
  37. super.onPostExecute(aVoid);
  38. mBtnPrint.setEnabled(true);
  39. }
  40.  
  41. public static Bitmap loadBitmapFromView(View v) {
  42.  
  43.  
  44. if (v.getMeasuredHeight() <= 0) {
  45. v.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
  46. Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
  47. Canvas c = new Canvas(b);
  48. v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
  49. v.draw(c);
  50. return b;
  51. }
  52.  
  53. Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
  54. Canvas c = new Canvas(b);
  55. v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
  56. v.draw(c);
  57.  
  58.  
  59. return b;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement