List of usage examples for android.view View getDrawingCache
@Deprecated
public Bitmap getDrawingCache()
Calling this method is equivalent to calling getDrawingCache(false)
.
From source file:devlight.io.library.TintLayout.java
@SuppressLint("DrawAllocation") @Override/*from w w w.ja v a 2s. co m*/ protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (getChildCount() > 1) throw new IllegalArgumentException(getResources().getString(R.string.child_exception)); final View child = getChildAt(0); ((LayoutParams) child.getLayoutParams()).gravity = Gravity.CENTER; child.setDrawingCacheEnabled(true); child.buildDrawingCache(); final Bitmap drawingCache = child.getDrawingCache(); if (drawingCache == null) return; // Obtain child screenshot mChildBitmap = Bitmap.createBitmap(drawingCache); drawingCache.recycle(); mChildBounds.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom()); child.setDrawingCacheEnabled(false); invalidateTint(); }
From source file:com.huewu.pla.sample.ImageDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate and locate the main ImageView final View v = inflater.inflate(R.layout.image_detail_fragment, container, false); mImageView = (ImageView) v.findViewById(R.id.imageView); mTextView = (TextView) v.findViewById(R.id.message); //setView/*from www . ja va 2 s. c o m*/ mTextView.setText(message); mImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.setDrawingCacheEnabled(true); Bitmap bitmap = v.getDrawingCache(); ZoomImageView zoom = new ZoomImageView(getActivity(), bitmap); zoom.showZoomView(); } }); return v; }
From source file:net.evendanan.android.hagarfingerpainting.HagarFingerpaintingActivity.java
private File takeScreenshot(boolean showToast) { View v = getWindow().getDecorView(); final int originalAdsVisibility = mAdView.getVisibility(); mAdView.setVisibility(View.INVISIBLE); mSettingsIcons.setVisibility(View.INVISIBLE); v.setDrawingCacheEnabled(true);/*w ww.j a v a 2 s . co m*/ Bitmap cachedBitmap = v.getDrawingCache(); Bitmap copyBitmap = cachedBitmap.copy(Bitmap.Config.RGB_565, true); FileOutputStream output = null; File file = null; try { File path = Places.getScreenshotFolder(); Calendar cal = Calendar.getInstance(); file = new File(path, getPainterName() + "_" + cal.get(Calendar.YEAR) + "_" + (1 + cal.get(Calendar.MONTH)) + "_" + cal.get(Calendar.DAY_OF_MONTH) + "_" + cal.get(Calendar.HOUR_OF_DAY) + "_" + cal.get(Calendar.MINUTE) + "_" + cal.get(Calendar.SECOND) + ".png"); output = new FileOutputStream(file); copyBitmap.compress(CompressFormat.PNG, 100, output); } catch (FileNotFoundException e) { file = null; e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } mAdView.setVisibility(originalAdsVisibility); mSettingsIcons.setVisibility(View.VISIBLE); } if (file != null) { if (showToast) Toast.makeText(getApplicationContext(), "Save fingerpainting to: " + file.getAbsolutePath(), Toast.LENGTH_LONG).show(); //sending a broadcast to the media scanner so it will scan the new screenshot. Intent requestScan = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); requestScan.setData(Uri.fromFile(file)); sendBroadcast(requestScan); return file; } else { return null; } }
From source file:org.androfarsh.widget.DragGridLayout.java
@SuppressWarnings("deprecation") private static BitmapDrawable createDrawingCache(View view) { BitmapDrawable drawable = null;/* w w w .j a v a 2 s . c o m*/ view.buildDrawingCache(); final Bitmap bitmap = view.getDrawingCache(); if (bitmap != null) { drawable = new BitmapDrawable(Bitmap.createBitmap(bitmap)); bitmap.recycle(); } view.destroyDrawingCache(); return drawable; }
From source file:com.kanchi.periyava.old.Activity.MainActivity.java
private void takeScreenshot() { Date now = new Date(); try {//from ww w. jav a 2s . c o m // image naming and path to include sd card appending name you // choose for file String mPath = Environment.getExternalStorageDirectory() + "/screenshot.png"; // create bitmap screen capture View v1 = getWindow().getDecorView().getRootView(); v1.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); File imageFile = new File(mPath); FileOutputStream outputStream = new FileOutputStream(imageFile); int quality = 100; bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); outputStream.flush(); outputStream.close(); } catch (Throwable e) { // Several error may come out with file handling or OOM e.printStackTrace(); } }
From source file:com.google.sample.cast.refplayer.chatting.MainActivity.java
public void takeScreenshot(View view) { Date now = new Date(); android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); try {//from w ww. j a va 2s .co m // image naming and path to include sd card appending name you choose for file //String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg"; String mPath = Environment.getExternalStorageDirectory().toString() + "/test3.jpg"; // create bitmap screen capture //View v1 = getWindow().getDecorView().getRootView(); View v1 = (RelativeLayout) findViewById(R.id.area_Screenshot); v1.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); File imageFile = new File(mPath); FileOutputStream outputStream = new FileOutputStream(imageFile); int quality = 100; bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); outputStream.flush(); outputStream.close(); //uploadImage("" + now); //uploadImage(); openScreenshot(imageFile); } catch (Throwable e) { // Several error may come out with file handling or OOM e.printStackTrace(); } }
From source file:org.openqa.selendroid.server.model.AbstractSelendroidDriver.java
@Override public byte[] takeScreenshot() { final View view = serverInstrumentation.getRootView(); if (view == null) { throw new SelendroidException("No open windows."); }/*from w w w. java 2 s . c o m*/ done = false; long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis(); final byte[][] rawPng = new byte[1][1]; ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { public void run() { synchronized (syncObject) { Bitmap raw; view.setDrawingCacheEnabled(true); view.buildDrawingCache(true); raw = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (!raw.compress(Bitmap.CompressFormat.PNG, 100, stream)) { throw new RuntimeException("Error while compressing screenshot image."); } try { stream.flush(); stream.close(); } catch (IOException e) { throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage()); } finally { IOUtils.closeQuietly(stream); } rawPng[0] = stream.toByteArray(); done = true; syncObject.notify(); } } }); waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot."); return rawPng[0]; }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
/** * This takes the screenshot of the whole screen. Is this a good thing? *///from w w w . jav a 2 s. c o m private File sendScreenshot(boolean showToast, ApiCallType callType, String label) { saveButton.setVisibility(View.INVISIBLE); loader.setVisibility(View.VISIBLE); View v = findViewById(R.id.CanvasId); v.setDrawingCacheEnabled(true); Bitmap cachedBitmap = v.getDrawingCache(); Bitmap copyBitmap = toGrayscale(cachedBitmap.copy(Bitmap.Config.RGB_565, true)); v.destroyDrawingCache(); FileOutputStream output = null; File file = null; try { File path = Places.getScreenshotFolder(); Calendar cal = Calendar.getInstance(); file = new File(path, cal.get(Calendar.YEAR) + "_" + (1 + cal.get(Calendar.MONTH)) + "_" + cal.get(Calendar.DAY_OF_MONTH) + "_" + cal.get(Calendar.HOUR_OF_DAY) + "_" + cal.get(Calendar.MINUTE) + "_" + cal.get(Calendar.SECOND) + ".jpg"); output = new FileOutputStream(file); copyBitmap.compress(CompressFormat.JPEG, 60, output); sendPost(file, callType, label); } catch (FileNotFoundException e) { file = null; e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } if (file != null) { if (showToast) Toast.makeText(getApplicationContext(), String .format(getResources().getString(R.string.saved_your_location_to), file.getAbsolutePath()), Toast.LENGTH_LONG).show(); /* // sending a broadcast to the media scanner so it will scan the new // screenshot. Intent requestScan = new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); requestScan.setData(Uri.fromFile(file)); sendBroadcast(requestScan); */ return file; } else { return null; } }
From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java
private void clickedOnUserBrick(final UserBrick clickedBrick, View view) { final Context context = getActivity(); final List<CharSequence> items = new ArrayList<CharSequence>(); items.add(context.getText(R.string.brick_context_dialog_add_to_script)); items.add(context.getText(R.string.brick_context_dialog_edit_brick)); AlertDialog.Builder builder = new AlertDialog.Builder(context); boolean drawingCacheEnabled = view.isDrawingCacheEnabled(); view.setDrawingCacheEnabled(true);// www . j ava 2 s . c o m view.setDrawingCacheBackgroundColor(Color.TRANSPARENT); view.buildDrawingCache(true); if (view.getDrawingCache() != null) { Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(drawingCacheEnabled); ImageView imageView = getGlowingBorder(bitmap); builder.setCustomTitle(imageView); } builder.setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { CharSequence clickedItemText = items.get(item); if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_add_to_script))) { addBrickToScript(clickedBrick); } else if (clickedItemText.equals(context.getText(R.string.brick_context_dialog_edit_brick))) { launchBrickScriptActivityOnBrick(context, clickedBrick); } } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java
public void storeImage(ImageView imageView) { Bitmap bm;/*from w w w. j a v a2 s . c o m*/ View v = imageView; v.setDrawingCacheEnabled(true); bm = Bitmap.createBitmap(v.getDrawingCache()); v.setDrawingCacheEnabled(false); String fileName = "image.png"; File file = new File(fileName); try { FileOutputStream fOut = openFileOutput(fileName, MODE_PRIVATE); bm.compress(Bitmap.CompressFormat.PNG, 100, fOut); } catch (Exception e) { e.printStackTrace(); } }