public BlurTask(View target, BlurFactor factor, Callback callback) { this.res = target.getResources(); this.factor = factor; this.callback = callback; this.contextWeakRef = new WeakReference<>(target.getContext()); target.setDrawingCacheEnabled(true); target.destroyDrawingCache(); target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); bitmap = target.getDrawingCache(); }
public static Bitmap of(View view, BlurFactor factor) { view.setDrawingCacheEnabled(true); view.destroyDrawingCache(); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); Bitmap cache = view.getDrawingCache(); Bitmap bitmap = of(view.getContext(), cache, factor); cache.recycle(); return bitmap; }
private Drawable buildCounterDrawable(int count, int backgroundImageId) { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.counter_menuitem_layout, null); view.setBackgroundResource(backgroundImageId); if (count == 0) { View counterTextPanel = view.findViewById(R.id.counterValuePanel); counterTextPanel.setVisibility(View.GONE); } else { TextView textView = (TextView) view.findViewById(R.id.count); textView.setText("" + count); } view.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); return new BitmapDrawable(getResources(), bitmap); }
View content = your_view; content.setDrawingCacheEnabled(true); content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = content.getDrawingCache(); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); File file = new File(path+"/image.png"); FileOutputStream ostream; try { file.createNewFile(); ostream = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); Toast.makeText(getApplicationContext(), "image saved", 5000).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "error", 5000).show(); }
private void save() { try { hideMenuBar(); View content = this; content.setDrawingCacheEnabled(true); content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = content.getDrawingCache(); String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/imotax/capture/spop/ttd/image"); if (!mFolder.exists()) { mFolder.mkdir(); } String s = "tmp.png"; File f = new File(mFolder.getAbsolutePath(), s); FileOutputStream fos = null; fos = new FileOutputStream(f); bitmap.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); bitmap.recycle(); Toast.makeText(getContext(), "image saved", 5000).show(); } catch (Exception e) { Toast.makeText(getContext(), "Failed To Save", 5000).show(); } }
public void run(RapidParserObject object, Object view, Var value) { String str = value.getString(); if( str.compareToIgnoreCase("DRAWING_CACHE_QUALITY_AUTO") == 0 ){ ((View)view).setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO); } else if( str.compareToIgnoreCase("DRAWING_CACHE_QUALITY_HIGH") == 0 ){ ((View)view).setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); } else if( str.compareToIgnoreCase("DRAWING_CACHE_QUALITY_LOW") == 0 ){ ((View)view).setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); } } }
@Override protected void onPreExecute() { super.onPreExecute(); decorView = activity.getWindow().getDecorView(); decorView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); decorView.setDrawingCacheEnabled(true); decorView.buildDrawingCache(); image = decorView.getDrawingCache(); }
View v = new View(context) { public void onMeasure(int w, int h) { setMeasuredDimension(width, height);//the desired width and height }}; //important v.setDrawingCacheEnabled(true); //important v.measure(width,height); //important the desired width and height v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); //important v.setDrawingCacheQuality(DRAWING_CACHE_QUALITY_HIGH); v.setLayoutParams(new LayoutParams(width,height)); //important v.buildDrawingCache(true); //important Bitmap b = v.getDrawingCache(true); v.buildDrawingCache(false);
public Bitmap takeScreenShot(View view) { view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); view.buildDrawingCache(); if (view.getDrawingCache() == null) return null; Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); view.destroyDrawingCache(); return snapshot; }
private static Bitmap loadBitmapFromView(View yourView) { Bitmap snapshot = null; Drawable drawable = null; yourView.setDrawingCacheEnabled(true); yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); //Quality of the snpashot try { yourView.buildDrawingCache(); // UPDATE HERE snapshot = Bitmap.createBitmap(yourView.getDrawingCache()); drawable = new BitmapDrawable(snapshot); } finally { yourView.setDrawingCacheEnabled(false); } return snapshot; }
public Bitmap takeScreenShot(View view) { // configuramos para que la view almacene la cache en una imagen view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); view.buildDrawingCache(); if(view.getDrawingCache() == null) return null; // Verificamos antes de que no sea null // utilizamos esa cache, para crear el bitmap que tendra la imagen de la view actual Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); view.destroyDrawingCache(); return snapshot; }
public static Bitmap screenshot(final View view) { view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); view.buildDrawingCache(); if (view.getDrawingCache() == null) { return null; } final Bitmap screenshot = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); view.destroyDrawingCache(); return screenshot; }
public Bitmap takeScreenShot(View view) { // configuramos para que la view almacene la cache en una imagen view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); view.buildDrawingCache(); if(view.getDrawingCache() == null) return null; // Verificamos antes de que no sea null // utilizamos esa cache, para crear el bitmap que tendra la imagen de la view actual Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); view.destroyDrawingCache(); return snapshot; }
private Drawable buildCounterDrawable(int count, int backgroundImageId) { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.counter_menuitem_layout, null); view.setBackgroundResource(backgroundImageId); if (count == 0) { View counterTextPanel = view.findViewById(R.id.counterValuePanel); counterTextPanel.setVisibility(View.GONE); } else { TextView textView = (TextView) view.findViewById(R.id.count); textView.setText("" + count); } view.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); return new BitmapDrawable(getResources(), bitmap); }
View content = drawView; content.setDrawingCacheEnabled(true); content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO); Bitmap bitmap; bitmap = content.getDrawingCache(); String file_name="MyImage"+System.currentTimeMillis()+".jpg"; ContentValues values = new ContentValues(); values.put(Images.Media.TITLE,"MyImage"); values.put(Images.Media.DESCRIPTION,"Advanced Practice"); values.put(Images.Media.MIME_TYPE, "image/jpeg"); Uri url = null; try { url = getContentResolver().insert(MediaStore.Images.Thumbnails.getContentUri("external"), values); MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"MyImage","Advanced Practice"); Toast.makeText(getApplicationContext(), " :) Image saved in /sdcard/DCIM/Camera/"+file_name, 5000).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), e.toString()+"error", 5000).show(); }
private Drawable buildCounterDrawable(int count, int backgroundImageId) { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.counter_menuitem_layout, null); view.setBackgroundResource(backgroundImageId); if (count == 0) { View counterTextPanel = view.findViewById(R.id.counterValuePanel); counterTextPanel.setVisibility(View.GONE); } else { TextView textView = (TextView) view.findViewById(R.id.count); textView.setText("" + count); } view.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); return new BitmapDrawable(getResources(), bitmap); }
private Drawable buildCounterDrawable(int count, int backgroundImageId) { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.counter_menuitem_layout, null); view.setBackgroundResource(backgroundImageId); if (count == 0) { View counterTextPanel = view.findViewById(R.id.counterValuePanel); counterTextPanel.setVisibility(View.GONE); } else { TextView textView = (TextView) view.findViewById(R.id.count); textView.setText("" + count); } view.measure( View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); return new BitmapDrawable(getResources(), bitmap); }
/** * Generates a screenshot of the specified `View` * * @param view the `View` component * @return the screenshot */ public static Bitmap getViewScreenshot(final View view) { // set up the drawing cache view.setDrawingCacheEnabled(true); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); // get the screenshot final Bitmap viewScreenshot = view.getDrawingCache(true); final Bitmap output = viewScreenshot.copy(viewScreenshot.getConfig(), false); // disable the drawing cache again view.destroyDrawingCache(); view.setDrawingCacheEnabled(false); return output; }
void getScreenCap(View yourView) { yourView.setDrawingCacheEnabled(true); yourView.setDrawingCacheQuality(LinearLayout.DRAWING_CACHE_QUALITY_HIGH); yourView.buildDrawingCache(); Bitmap bmp = null; if (yourView != null) { try { bmp = Bitmap.createBitmap(yourView.getDrawingCache()); } catch (NullPointerException e) { } } yourView.setDrawingCacheEnabled(false); yourView.destroyDrawingCache(); if (bmp != null) { String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/"; File dir = new File(file_path); if (!dir.exists()) { dir.mkdirs(); } File file = new File(dir, "screencap.png"); FileOutputStream fOut = null; try { fOut = new FileOutputStream(file); } catch (FileNotFoundException e1) { } bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut); try { fOut.flush(); fOut.close(); } catch (IOException e1) { } } }
private Bitmap prepareAndSetBitmap(final View targetView) { targetView.setDrawingCacheEnabled(true); targetView.destroyDrawingCache(); targetView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_AUTO); targetView.buildDrawingCache(true); Bitmap sourceBitmap = Bitmap.createBitmap(targetView.getDrawingCache()); targetView.setDrawingCacheEnabled(false); targetView.destroyDrawingCache(); Bitmap overlay = Bitmap.createBitmap((int) (targetView.getMeasuredWidth() / scaleFactor), (int) (targetView.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); // canvas.translate(-targetView.getLeft() / scaleFactor, -targetView.getTop() / scaleFactor); canvas.scale(1 / scaleFactor, 1 / scaleFactor); Paint paint = new Paint(); paint.setColor(Color.RED); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(sourceBitmap, 0, 0, paint); // canvas.drawColor(Color.RED); sourceBitmap.recycle(); return FastBlur.doBlur(overlay, radius, false); }