List of usage examples for android.graphics Paint FILTER_BITMAP_FLAG
int FILTER_BITMAP_FLAG
To view the source code for android.graphics Paint FILTER_BITMAP_FLAG.
Click Source Link
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
private void ensureCollapsedTexture() { if (mCollapsedTitleTexture != null || mCollapsedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) { return;//from w w w .j av a2 s . c om } calculateOffsets(0f); final int w = Math.round(mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length())); final int h = Math.round(mTextPaint.descent() - mTextPaint.ascent()); if (w <= 0 && h <= 0) { return; // If the width or height are 0, return } mCollapsedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(mCollapsedTitleTexture); c.drawText(mTextToDrawCollapsed, 0, mTextToDrawCollapsed.length(), 0, -mTextPaint.ascent() / mScale, mTextPaint); if (mTexturePaint == null) { // Make sure we have a paint mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); } }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
private void ensureCrossSectionTexture() { if (mCrossSectionTitleTexture != null || mCollapsedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) { return;// ww w . jav a 2s . c o m } calculateOffsets(0f); final int w = Math .round(mTextPaint.measureText(mTextToDraw, mTextLayout.getLineStart(0), mTextLayout.getLineEnd(0))); final int h = Math.round(mTextPaint.descent() - mTextPaint.ascent()); if (w <= 0 && h <= 0) { return; // If the width or height are 0, return } mCrossSectionTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(mCrossSectionTitleTexture); c.drawText(mTextToDraw, mTextLayout.getLineStart(0), mTextLayout.getLineEnd(0), 0, -mTextPaint.ascent() / mScale, mTextPaint); if (mTexturePaint == null) { // Make sure we have a paint mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); } }
From source file:android.support.design.widget.CustomCollapsingTextHelper.java
private void ensureExpandedTexture() { if (mExpandedTitleTexture != null || mExpandedBounds.isEmpty() || TextUtils.isEmpty(mTextToDraw)) { return;//from w ww . j a v a 2 s . c om } calculateOffsets(0f); mTextureAscent = mTitlePaint.ascent(); mTextureDescent = mTitlePaint.descent(); final int w = Math.round(mTitlePaint.measureText(mTextToDraw, 0, mTextToDraw.length())); final int h = Math.round(mTextureDescent - mTextureAscent); if (w <= 0 || h <= 0) { return; // If the width or height are 0, return } mExpandedTitleTexture = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(mExpandedTitleTexture); c.drawText(mTextToDraw, 0, mTextToDraw.length(), 0, h - mTitlePaint.descent(), mTitlePaint); if (mTexturePaint == null) { // Make sure we have a paint mTexturePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); } }
From source file:com.android.launcher3.Utilities.java
/** * Adds the {@param badge} on top of {@param srcTgt} using the badge dimensions. *///w ww . ja v a 2 s .co m @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static Bitmap badgeWithBitmap(Bitmap srcTgt, Bitmap badge, Context context) { int badgeSize = context.getResources().getDimensionPixelSize(R.dimen.profile_badge_size); synchronized (sCanvas) { sCanvas.setBitmap(srcTgt); sCanvas.drawBitmap(badge, new Rect(0, 0, badge.getWidth(), badge.getHeight()), new Rect(srcTgt.getWidth() - badgeSize, srcTgt.getHeight() - badgeSize, srcTgt.getWidth(), srcTgt.getHeight()), new Paint(Paint.FILTER_BITMAP_FLAG)); sCanvas.setBitmap(null); } return srcTgt; }
From source file:com.affectiva.affdexme.MainActivity.java
private void processScreenshot(Bitmap drawingViewBitmap, boolean alsoSaveRaw) { if (mostRecentFrame == null) { Toast.makeText(getApplicationContext(), "No frame detected, aborting screenshot", Toast.LENGTH_SHORT) .show();//from w ww . j ava 2 s . c o m return; } if (!storagePermissionsAvailable) { checkForStoragePermissions(); return; } Bitmap faceBitmap = ImageHelper.getBitmapFromFrame(mostRecentFrame); if (faceBitmap == null) { Log.e(LOG_TAG, "Unable to generate bitmap for frame, aborting screenshot"); return; } metricViewLayout.setDrawingCacheEnabled(true); Bitmap metricsBitmap = Bitmap.createBitmap(metricViewLayout.getDrawingCache()); metricViewLayout.setDrawingCacheEnabled(false); Bitmap finalScreenshot = Bitmap.createBitmap(faceBitmap.getWidth(), faceBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(finalScreenshot); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(faceBitmap, 0, 0, paint); float scaleFactor = ((float) faceBitmap.getWidth()) / ((float) drawingViewBitmap.getWidth()); int scaledHeight = Math.round(drawingViewBitmap.getHeight() * scaleFactor); canvas.drawBitmap(drawingViewBitmap, null, new Rect(0, 0, faceBitmap.getWidth(), scaledHeight), paint); scaleFactor = ((float) faceBitmap.getWidth()) / ((float) metricsBitmap.getWidth()); scaledHeight = Math.round(metricsBitmap.getHeight() * scaleFactor); canvas.drawBitmap(metricsBitmap, null, new Rect(0, 0, faceBitmap.getWidth(), scaledHeight), paint); metricsBitmap.recycle(); drawingViewBitmap.recycle(); Date now = new Date(); String timestamp = DateFormat.format("yyyy-MM-dd_hh-mm-ss", now).toString(); File pictureFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "AffdexMe"); if (!pictureFolder.exists()) { if (!pictureFolder.mkdir()) { Log.e(LOG_TAG, "Unable to create directory: " + pictureFolder.getAbsolutePath()); return; } } String screenshotFileName = timestamp + ".png"; File screenshotFile = new File(pictureFolder, screenshotFileName); try { ImageHelper.saveBitmapToFileAsPng(finalScreenshot, screenshotFile); } catch (IOException e) { String msg = "Unable to save screenshot"; Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); Log.e(LOG_TAG, msg, e); return; } ImageHelper.addPngToGallery(getApplicationContext(), screenshotFile); if (alsoSaveRaw) { String rawScreenshotFileName = timestamp + "_raw.png"; File rawScreenshotFile = new File(pictureFolder, rawScreenshotFileName); try { ImageHelper.saveBitmapToFileAsPng(faceBitmap, rawScreenshotFile); } catch (IOException e) { String msg = "Unable to save screenshot"; Log.e(LOG_TAG, msg, e); } ImageHelper.addPngToGallery(getApplicationContext(), rawScreenshotFile); } faceBitmap.recycle(); finalScreenshot.recycle(); String fileSavedMessage = "Screenshot saved to: " + screenshotFile.getPath(); Toast.makeText(getApplicationContext(), fileSavedMessage, Toast.LENGTH_SHORT).show(); Log.d(LOG_TAG, fileSavedMessage); }
From source file:g7.bluesky.launcher3.Launcher.java
public void loadIconPack() { //theming vars----------------------------------------------- PackageManager pm = getPackageManager(); final int ICONSIZE = Tools.numtodp(64, Launcher.this); Resources themeRes = null;//w w w . ja v a 2 s . co m String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, ""); String iconResource = null; int intres = 0; int intresiconback = 0; int intresiconfront = 0; int intresiconmask = 0; float scaleFactor = 1.0f; Paint p = new Paint(Paint.FILTER_BITMAP_FLAG); p.setAntiAlias(true); Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG); origP.setAntiAlias(true); Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG); maskp.setAntiAlias(true); maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); if (resPacName.compareTo("") != 0) { try { themeRes = pm.getResourcesForApplication(resPacName); } catch (Exception e) { } ; if (themeRes != null) { String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName); if (backAndMaskAndFront[0] != null) intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName); if (backAndMaskAndFront[1] != null) intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName); if (backAndMaskAndFront[2] != null) intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName); } } BitmapFactory.Options uniformOptions = new BitmapFactory.Options(); uniformOptions.inScaled = false; uniformOptions.inDither = false; uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Canvas origCanv; Canvas canvas; scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName); Bitmap back = null; Bitmap mask = null; Bitmap front = null; Bitmap scaledBitmap = null; Bitmap scaledOrig = null; Bitmap orig = null; if (resPacName.compareTo("") != 0 && themeRes != null) { try { if (intresiconback != 0) back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions); } catch (Exception e) { } try { if (intresiconmask != 0) mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions); } catch (Exception e) { } try { if (intresiconfront != 0) front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions); } catch (Exception e) { } } //theming vars----------------------------------------------- BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; for (int i = 0; i < listApps.size(); i++) { if (themeRes != null) { iconResource = null; intres = 0; iconResource = ThemeTools.getResourceName(themeRes, resPacName, listApps.get(i).getComponentName().toString()); if (iconResource != null) { intres = themeRes.getIdentifier(iconResource, "drawable", resPacName); } if (intres != 0) {//has single drawable for app listApps.get(i).setIconBitmap(BitmapFactory.decodeResource(themeRes, intres, uniformOptions)); } else { Drawable drawable = listApps.get(i).getIconDrawable(); if (drawable == null) { drawable = Utilities.createIconDrawable(listApps.get(i).getIconBitmap()); } orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(new Canvas(orig)); scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); canvas = new Canvas(scaledBitmap); if (back != null) { canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p); } origCanv = new Canvas(scaledOrig); orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)), ((int) (ICONSIZE * scaleFactor))); origCanv.drawBitmap(orig, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP); if (mask != null) { origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp); } if (back != null) { canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); } else canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); if (front != null) canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p); listApps.get(i).setIconBitmap(scaledBitmap); } } } }
From source file:g7.bluesky.launcher3.Launcher.java
public void loadIconPack(List<ShortcutInfo> shortcuts) { //theming vars----------------------------------------------- PackageManager pm = getPackageManager(); final int ICONSIZE = Tools.numtodp(128, Launcher.this); Resources themeRes = null;//w w w.j a va2s.c om String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, ""); String iconResource = null; int intres = 0; int intresiconback = 0; int intresiconfront = 0; int intresiconmask = 0; float scaleFactor = 1.0f; Paint p = new Paint(Paint.FILTER_BITMAP_FLAG); p.setAntiAlias(true); Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG); origP.setAntiAlias(true); Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG); maskp.setAntiAlias(true); maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); if (resPacName.compareTo("") != 0) { try { themeRes = pm.getResourcesForApplication(resPacName); } catch (Exception e) { } ; if (themeRes != null) { String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName); if (backAndMaskAndFront[0] != null) intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName); if (backAndMaskAndFront[1] != null) intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName); if (backAndMaskAndFront[2] != null) intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName); } } BitmapFactory.Options uniformOptions = new BitmapFactory.Options(); uniformOptions.inScaled = false; uniformOptions.inDither = false; uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Canvas origCanv; Canvas canvas; scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName); Bitmap back = null; Bitmap mask = null; Bitmap front = null; Bitmap scaledBitmap = null; Bitmap scaledOrig = null; Bitmap orig = null; if (resPacName.compareTo("") != 0 && themeRes != null) { try { if (intresiconback != 0) back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions); } catch (Exception e) { } try { if (intresiconmask != 0) mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions); } catch (Exception e) { } try { if (intresiconfront != 0) front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions); } catch (Exception e) { } } //theming vars----------------------------------------------- BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; for (int i = 0; i < shortcuts.size(); i++) { if (themeRes != null) { iconResource = null; intres = 0; iconResource = ThemeTools.getResourceName(themeRes, resPacName, shortcuts.get(i).getTargetComponent().toString()); if (iconResource != null) { intres = themeRes.getIdentifier(iconResource, "drawable", resPacName); } if (intres != 0) {//has single drawable for app shortcuts.get(i).setIcon(BitmapFactory.decodeResource(themeRes, intres, uniformOptions)); } else { Drawable drawable = Utilities.createIconDrawable(shortcuts.get(i).getIcon(mIconCache)); orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(new Canvas(orig)); scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); canvas = new Canvas(scaledBitmap); if (back != null) { canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p); } origCanv = new Canvas(scaledOrig); orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)), ((int) (ICONSIZE * scaleFactor))); origCanv.drawBitmap(orig, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP); if (mask != null) { origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp); } if (back != null) { canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); } else canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); if (front != null) canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p); shortcuts.get(i).setIcon(scaledBitmap); } } } }