Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class Test extends AsyncTask<Void,Void,Void>{
- @Override
- protected Void doInBackground(Void... voids) {
- Bitmap m = loadBitmapFromView(l);
- replaceColor(m,Color.BLACK, Color.WHITE);
- ImageView i = findViewById(R.id.bm);
- String root = Environment.getExternalStorageDirectory().toString();
- File myDir = new File(root + "/req_images");
- myDir.mkdirs();
- int n = 1;
- String fname = "Image-" + n + ".jpg";
- File file = new File(myDir, fname);
- Log.i(TAG, "" + file);
- if (file.exists())
- file.delete();
- try {
- FileOutputStream out = new FileOutputStream(file);
- m.compress(Bitmap.CompressFormat.JPEG, 100, out);
- out.flush();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- mFiles.add(file.getPath());
- return null;
- }
- @Override
- protected void onPostExecute(Void aVoid) {
- super.onPostExecute(aVoid);
- mBtnPrint.setEnabled(true);
- }
- public static Bitmap loadBitmapFromView(View v) {
- if (v.getMeasuredHeight() <= 0) {
- v.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.MATCH_PARENT);
- Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(b);
- v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
- v.draw(c);
- return b;
- }
- Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(b);
- v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
- v.draw(c);
- return b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement