Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- view.setDrawingCacheEnabled(true);
- Bitmap bitmap = view.getDrawingCache();
- try {
- FileOutputStream stream = new FileOutputStream(getApplicationContext().getCacheDir() + "/image.jpg");
- bitmap.compress(CompressFormat.JPEG, 80, stream);
- stream.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- view.setDrawingCacheEnabled(false);
- final boolean cachePreviousState = view.isDrawingCacheEnabled();
- final int backgroundPreviousColor = view.getDrawingCacheBackgroundColor();
- view.setDrawingCacheEnabled(true);
- view.setDrawingCacheBackgroundColor(0xfffafafa);
- final Bitmap bitmap = view.getDrawingCache();
- view.setDrawingCacheBackgroundColor(backgroundPreviousColor);
- bitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);
- view.setDrawingCacheEnabled(cachePreviousState);
- public Bitmap loadBitmapFromView(View v) {
- DisplayMetrics dm = getResources().getDisplayMetrics();
- v.measure(View.MeasureSpec.makeMeasureSpec(dm.widthPixels,
- View.MeasureSpec.EXACTLY),
- View.MeasureSpec.makeMeasureSpec(dm.heightPixels,
- View.MeasureSpec.EXACTLY));
- v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
- Bitmap returnedBitmap =
- Bitmap.createBitmap(v.getMeasuredWidth(),
- v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(returnedBitmap);
- v.draw(c);
- return returnedBitmap;
- }
Add Comment
Please, Sign In to add comment