private void eraseBitmap(Bitmap bmp) { if (bmp != null) { bmp.eraseColor(Color.TRANSPARENT); } }
Bitmap b = /*however you get a bmp*/ b.eraseColor(color)
@Override @NonNull public Bitmap get(int width, int height, Bitmap.Config config) { Bitmap result = getDirtyOrNull(width, height, config); if (result != null) { // Bitmaps in the pool contain random data that in some cases must be cleared for an image // to be rendered correctly. we shouldn't force all consumers to independently erase the // contents individually, so we do so here. See issue #131. result.eraseColor(Color.TRANSPARENT); } else { result = createBitmap(width, height, config); } return result; }
bitmap.eraseColor(0);
protected Bitmap createTestBitmap(int size) { Bitmap image = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565); image.eraseColor(Color.BLUE); return image; }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); mEraserBitmap.eraseColor(Color.TRANSPARENT); mEraserCanvas.drawColor(mFullingPaint.getColor()); if (!mOverlayTarget) { switch (mStyle) { case Component.ROUNDRECT: mEraserCanvas.drawRoundRect(mTargetRect, mCorner, mCorner, mEraser); break; case Component.CIRCLE: mEraserCanvas.drawCircle(mTargetRect.centerX(), mTargetRect.centerY(), mTargetRect.width() / 2, mEraser); break; default: mEraserCanvas.drawRoundRect(mTargetRect, mCorner, mCorner, mEraser); break; } canvas.drawBitmap(mEraserBitmap, 0, 0, null); } }
createCachedBitmapIfNeeded(width, height); if (mCacheDirty) { mCachedBitmap.eraseColor(Color.TRANSPARENT); Canvas tmpCanvas = new Canvas(mCachedBitmap); drawCachedBitmap(tmpCanvas);
public BitmapDrawable rotateDrawable(float angle) { Bitmap arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.map_pin); // Create blank bitmap of equal size Bitmap canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_8888, true); canvasBitmap.eraseColor(0x00000000); // Create canvas Canvas canvas = new Canvas(canvasBitmap); // Create rotation matrix Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(angle, canvas.getWidth()/2, canvas.getHeight()/2); // Draw bitmap onto canvas using matrix canvas.drawBitmap(arrowBitmap, rotateMatrix, null); return new BitmapDrawable(canvasBitmap); }
@Override public void drawData(Canvas c) { int width = (int) mViewPortHandler.getChartWidth(); int height = (int) mViewPortHandler.getChartHeight(); Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get(); if (drawBitmap == null || (drawBitmap.getWidth() != width) || (drawBitmap.getHeight() != height)) { if (width > 0 && height > 0) { drawBitmap = Bitmap.createBitmap(width, height, mBitmapConfig); mDrawBitmap = new WeakReference<>(drawBitmap); mBitmapCanvas = new Canvas(drawBitmap); } else return; } drawBitmap.eraseColor(Color.TRANSPARENT); LineData lineData = mChart.getLineData(); for (ILineDataSet set : lineData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } c.drawBitmap(drawBitmap, 0, 0, mRenderPaint); }
public Bitmap getBitmap(int position) { int index = getIndexFromPosition(position); if (bitmaps[index] == null) { createBitmapAtIndex(index); } bitmaps[index].eraseColor(Color.TRANSPARENT); return bitmaps[index]; }
public void apply() { mBitmap.eraseColor(0); for (Path path : mPathStack) { mCanvas.drawPath(path, mPaint); } for (PointF point : mPointStack) { mCanvas.drawPoint(point.x, point.y, mPaint); } invalidate(); } }
public static Bitmap getThemeDrawable(int theme) { Bitmap bmp = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight(), Bitmap.Config.ARGB_8888); switch (theme) { case NORMAL: bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_white)); break; case YELLOW: bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_yellow)); break; case GREEN: bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_green)); break; case LEATHER: bmp = BitmapFactory.decodeResource(AppUtils.getAppContext().getResources(), R.drawable.theme_leather_bg); break; case GRAY: bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_gray)); break; case NIGHT: bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_night)); break; default: break; } return bmp; }
@Override public void drawData(Canvas c) { int width = (int) mViewPortHandler.getChartWidth(); int height = (int) mViewPortHandler.getChartHeight(); Bitmap drawBitmap = mDrawBitmap == null ? null : mDrawBitmap.get(); if (drawBitmap == null || (drawBitmap.getWidth() != width) || (drawBitmap.getHeight() != height)) { if (width > 0 && height > 0) { drawBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); mDrawBitmap = new WeakReference<>(drawBitmap); mBitmapCanvas = new Canvas(drawBitmap); } else return; } drawBitmap.eraseColor(Color.TRANSPARENT); PieData pieData = mChart.getData(); for (IPieDataSet set : pieData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
/** * Clear the whiteboard. */ public void clear() { mUndoModeActive = false; mBitmap.eraseColor(0); mUndo.clear(); invalidate(); if (mCardViewer.get() != null) { mCardViewer.get().supportInvalidateOptionsMenu(); } }
void setPage(PdfRenderer.Page page) { if (bitmap==null) { int height=2000; int width=height * page.getWidth() / page.getHeight(); bitmap=Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); } bitmap.eraseColor(0xFFFFFFFF); page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); iv.resetScaleAndCenter(); iv.setImage(ImageSource.cachedBitmap(bitmap)); } }
public void update() throws TextureException { if(mMovie == null || mMovie.duration() == 0) return; long now = SystemClock.uptimeMillis(); int relTime = (int)((now - mStartTime) % mMovie.duration()); mMovie.setTime(relTime); mGIFBitmap.eraseColor(Color.TRANSPARENT); mMovie.draw(mCanvas, 0, 0); mBitmap = Bitmap.createScaledBitmap(mGIFBitmap, mTextureSize, mTextureSize, false); TextureManager.getInstance().replaceTexture(this); replace(); }
@Test public void testCopyAndEraseColor() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Bitmap copy = bitmap.copy(Bitmap.Config.ARGB_8888, true); copy.eraseColor(0xffff0000); assertThat(copy.getPixel(10, 10)).isEqualTo(0xffff0000); assertThat(copy.getPixel(50, 50)).isEqualTo(0xffff0000); }
@Test public void testEraseColor() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); bitmap.eraseColor(0xffff0000); assertThat(bitmap.getPixel(10, 10)).isEqualTo(0xffff0000); assertThat(bitmap.getPixel(50, 50)).isEqualTo(0xffff0000); }
bitmap.eraseColor(Color.TRANSPARENT); canvas.setBitmap(bitmap); recycleBitmapArray();
GifDrawable(GifInfoHandle gifInfoHandle, final GifDrawable oldDrawable, ScheduledThreadPoolExecutor executor, boolean isRenderingTriggeredOnDraw) { mIsRenderingTriggeredOnDraw = isRenderingTriggeredOnDraw; mExecutor = executor != null ? executor : GifRenderingExecutor.getInstance(); mNativeInfoHandle = gifInfoHandle; Bitmap oldBitmap = null; if (oldDrawable != null) { synchronized (oldDrawable.mNativeInfoHandle) { if (!oldDrawable.mNativeInfoHandle.isRecycled() && oldDrawable.mNativeInfoHandle.getHeight() >= mNativeInfoHandle.getHeight() && oldDrawable.mNativeInfoHandle.getWidth() >= mNativeInfoHandle.getWidth()) { oldDrawable.shutdown(); oldBitmap = oldDrawable.mBuffer; oldBitmap.eraseColor(Color.TRANSPARENT); } } } if (oldBitmap == null) { mBuffer = Bitmap.createBitmap(mNativeInfoHandle.getWidth(), mNativeInfoHandle.getHeight(), Bitmap.Config.ARGB_8888); } else { mBuffer = oldBitmap; } mBuffer.setHasAlpha(!gifInfoHandle.isOpaque()); mSrcRect = new Rect(0, 0, mNativeInfoHandle.getWidth(), mNativeInfoHandle.getHeight()); mInvalidationHandler = new InvalidationHandler(this); mRenderTask.doWork(); mScaledWidth = mNativeInfoHandle.getWidth(); mScaledHeight = mNativeInfoHandle.getHeight(); }