android.graphics.Bitmap.eraseColor()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(413)

本文整理了Java中android.graphics.Bitmap.eraseColor()方法的一些代码示例,展示了Bitmap.eraseColor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.eraseColor()方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:eraseColor

Bitmap.eraseColor介绍

暂无

代码示例

代码示例来源:origin: Bilibili/DanmakuFlameMaster

private void eraseBitmap(Bitmap bmp) {
  if (bmp != null) {
    bmp.eraseColor(Color.TRANSPARENT);
  }
}

代码示例来源:origin: stackoverflow.com

Bitmap b = /*however you get a bmp*/
b.eraseColor(color)

代码示例来源:origin: bumptech/glide

@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;
}

代码示例来源:origin: stackoverflow.com

bitmap.eraseColor(0);

代码示例来源:origin: facebook/facebook-android-sdk

protected Bitmap createTestBitmap(int size) {
  Bitmap image = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
  image.eraseColor(Color.BLUE);
  return image;
}

代码示例来源:origin: binIoter/GuideView

@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);
 }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

createCachedBitmapIfNeeded(width, height);
if (mCacheDirty) {
  mCachedBitmap.eraseColor(Color.TRANSPARENT);
  Canvas tmpCanvas = new Canvas(mCachedBitmap);
  drawCachedBitmap(tmpCanvas);

代码示例来源:origin: stackoverflow.com

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); 
}

代码示例来源:origin: PhilJay/MPAndroidChart

@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);
}

代码示例来源:origin: smuyyh/BookReader

public Bitmap getBitmap(int position) {
  int index = getIndexFromPosition(position);
  if (bitmaps[index] == null) {
    createBitmapAtIndex(index);
  }
  bitmaps[index].eraseColor(Color.TRANSPARENT);
  return bitmaps[index];
}

代码示例来源:origin: ankidroid/Anki-Android

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();
  }
}

代码示例来源:origin: smuyyh/BookReader

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;
}

代码示例来源:origin: PhilJay/MPAndroidChart

@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);
  }
}

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Clear the whiteboard.
 */
public void clear() {
  mUndoModeActive = false;
  mBitmap.eraseColor(0);
  mUndo.clear();
  invalidate();
  if (mCardViewer.get() != null) {
    mCardViewer.get().supportInvalidateOptionsMenu();
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

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));
 }
}

代码示例来源:origin: Rajawali/Rajawali

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();
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: robolectric/robolectric

@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);
}

代码示例来源:origin: Bilibili/DanmakuFlameMaster

bitmap.eraseColor(Color.TRANSPARENT);
canvas.setBitmap(bitmap);
recycleBitmapArray();

代码示例来源:origin: koral--/android-gif-drawable

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();
}

相关文章