Tabnine Logo
BitmapShader
Code IndexAdd Tabnine to your IDE (free)

How to use
BitmapShader
in
android.graphics

Best Java code snippets using android.graphics.BitmapShader (Showing top 20 results out of 2,331)

origin: nostra13/Android-Universal-Image-Loader

public RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {
  this.cornerRadius = cornerRadius;
  this.margin = margin;
  bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  mBitmapRect = new RectF (margin, margin, bitmap.getWidth() - margin, bitmap.getHeight() - margin);
  
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(bitmapShader);
  paint.setFilterBitmap(true);
  paint.setDither(true);
}
origin: rey5137/material

public void setImage(Bitmap bm){
  if(mBitmap != bm){
    mBitmap = bm;
    if(mBitmap != null) {
      mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
      mMatrix.reset();
      float scale = mHeight / (float)Math.min(mBitmap.getWidth(), mBitmap.getHeight());
      mMatrix.setScale(scale, scale, 0, 0);
      mMatrix.postTranslate((mHeight  - mBitmap.getWidth() * scale) / 2, (mHeight - mBitmap.getHeight() * scale) / 2);
      mBitmapShader.setLocalMatrix(mMatrix);
    }
  }
}
origin: hdodenhof/CircleImageView

private void updateShaderMatrix() {
  float scale;
  float dx = 0;
  float dy = 0;
  mShaderMatrix.set(null);
  if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
    scale = mDrawableRect.height() / (float) mBitmapHeight;
    dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
  } else {
    scale = mDrawableRect.width() / (float) mBitmapWidth;
    dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
  }
  mShaderMatrix.setScale(scale, scale);
  mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top);
  mBitmapShader.setLocalMatrix(mShaderMatrix);
}
origin: Neamar/KISS

@Override
protected void onBoundsChange(Rect bounds) {
  super.onBoundsChange(bounds);
  Matrix m = new Matrix();
  mBitmapShader.getLocalMatrix(m);
  // Scale bitmap to display within specified bounds
  int minScale = Math.min(bounds.width(), bounds.height());
  m.setScale(minScale / mBitmapRect.width(), minScale / mBitmapRect.height());
  // When bounds is not a square, ensure we display the bitmap centered
  // (we will clip to display as a centered circle,
  //  and we need to ensure the bitmap is in the right position below)
  if (bounds.width() > bounds.height()) {
    m.postTranslate((bounds.width() - bounds.height()) * 0.5f, 0f);
  }
  mBitmapShader.setLocalMatrix(m);
  mDisplayBounds.set(bounds);
}
origin: nostra13/Android-Universal-Image-Loader

@Override
protected void onBoundsChange(Rect bounds) {
  super.onBoundsChange(bounds);
  mRect.set(0, 0, bounds.width(), bounds.height());
  radius = Math.min(bounds.width(), bounds.height()) / 2;
  strokeRadius = radius - strokeWidth / 2;
  // Resize the original bitmap to fit the new bound
  Matrix shaderMatrix = new Matrix();
  shaderMatrix.setRectToRect(mBitmapRect, mRect, Matrix.ScaleToFit.FILL);
  bitmapShader.setLocalMatrix(shaderMatrix);
}
origin: nostra13/Android-Universal-Image-Loader

public CircleDrawable(Bitmap bitmap, Integer strokeColor, float strokeWidth) {
  radius = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2;
  bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  mBitmapRect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(bitmapShader);
  paint.setFilterBitmap(true);
  paint.setDither(true);
  if (strokeColor == null) {
    strokePaint = null;
  } else {
    strokePaint = new Paint();
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setColor(strokeColor);
    strokePaint.setStrokeWidth(strokeWidth);
    strokePaint.setAntiAlias(true);
  }
  this.strokeWidth = strokeWidth;
  strokeRadius = radius - strokeWidth / 2;
}
origin: cymcsg/UltimateAndroid

/**
 * Re-initializes the shader texture used to fill in
 * the Circle upon drawing.
 */
public void updateBitmapShader() {
  if (image == null)
    return;
  shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  if(canvasSize != image.getWidth() || canvasSize != image.getHeight()) {
    Matrix matrix = new Matrix();
    float scale = (float) canvasSize / (float) image.getWidth();
    matrix.setScale(scale, scale);
    shader.setLocalMatrix(matrix);
  }
}
origin: nostra13/Android-Universal-Image-Loader

@Override
protected void onBoundsChange(Rect bounds) {
  super.onBoundsChange(bounds);
  mRect.set(margin, margin, bounds.width() - margin, bounds.height() - margin);
  
  // Resize the original bitmap to fit the new bound
  Matrix shaderMatrix = new Matrix();
  shaderMatrix.setRectToRect(mBitmapRect, mRect, Matrix.ScaleToFit.FILL);
  bitmapShader.setLocalMatrix(shaderMatrix);
  
}
origin: smuyyh/BookReader

private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
  if (source == null) return null;
  Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  if (result == null) {
    result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  }
  Canvas canvas = new Canvas(result);
  Paint paint = new Paint();
  paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
  paint.setAntiAlias(true);
  RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
  canvas.drawRoundRect(rectF, radius, radius, paint);
  return result;
}
origin: Bearded-Hen/Android-Bootstrap

BitmapShader imageShader = new BitmapShader(sourceBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
imagePaint.setShader(imageShader);
matrix.postTranslate((dx + 0.5f), (dy + 0.5f));
imageShader.setLocalMatrix(matrix);
imageRectF.set(0, 0, viewWidth, viewHeight);
origin: rey5137/material

private void updateMatrix(){
  if(mBitmap == null)
    return;
  Rect bounds = getBounds();
  if(bounds.width() == 0 || bounds.height() == 0)
    return;
  mMatrix.reset();
  float scale = bounds.height() / (float)Math.min(mBitmap.getWidth(), mBitmap.getHeight());
  mMatrix.setScale(scale, scale, 0, 0);
  mMatrix.postTranslate((bounds.height()  - mBitmap.getWidth() * scale) / 2, (bounds.height() - mBitmap.getHeight() * scale) / 2);
  mBitmapShader.setLocalMatrix(mMatrix);
}
origin: siyamed/android-shape-imageview

protected void createShader() {
  Bitmap bitmap = calculateDrawableSizes();
  if(bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) {
    shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    imagePaint.setShader(shader);
  }
}
origin: mmin18/RealtimeBlurView

  /**
   * Custom oval shape
   */
  @Override
  protected void drawBlurredBitmap(Canvas canvas, Bitmap blurredBitmap, int overlayColor) {
    if (blurredBitmap != null) {
      mRectF.right = getWidth();
      mRectF.bottom = getHeight();

      mPaint.reset();
      mPaint.setAntiAlias(true);
      BitmapShader shader = new BitmapShader(blurredBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
      Matrix matrix = new Matrix();
      matrix.postScale(mRectF.width() / blurredBitmap.getWidth(), mRectF.height() / blurredBitmap.getHeight());
      shader.setLocalMatrix(matrix);
      mPaint.setShader(shader);
      canvas.drawOval(mRectF, mPaint);

      mPaint.reset();
      mPaint.setAntiAlias(true);
      mPaint.setColor(overlayColor);
      canvas.drawOval(mRectF, mPaint);
    }
  }
}
origin: naman14/Timber

private void updateShaderMatrix() {
  float scale;
  float dx = 0;
  float dy = 0;
  mShaderMatrix.set(null);
  if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
    scale = mDrawableRect.height() / (float) mBitmapHeight;
    dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
  } else {
    scale = mDrawableRect.width() / (float) mBitmapWidth;
    dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
  }
  mShaderMatrix.setScale(scale, scale);
  mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top);
  mBitmapShader.setLocalMatrix(mShaderMatrix);
}
origin: frogermcs/InstaMaterial

@Override
public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());
  int x = (source.getWidth() - size) / 2;
  int y = (source.getHeight() - size) / 2;
  Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
  if (squaredBitmap != source) {
    source.recycle();
  }
  Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  paint.setShader(shader);
  paint.setAntiAlias(true);
  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);
  squaredBitmap.recycle();
  return bitmap;
}
origin: alexvasilkov/GestureViews

private void setup() {
  init();
  Bitmap bitmap = isCircle ? getBitmapFromDrawable(getDrawable()) : null;
  if (bitmap != null) {
    BitmapShader bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    tmpMatrix.set(getImageMatrix());
    tmpMatrix.postTranslate(getPaddingLeft(), getPaddingTop());
    bitmapShader.setLocalMatrix(tmpMatrix);
    bitmapPaint.setShader(bitmapShader);
  } else {
    bitmapPaint.setShader(null);
  }
  invalidate();
}
origin: aa112901/remusic

private void updateShaderMatrix() {
  float scale;
  float dx = 0;
  float dy = 0;
  mShaderMatrix.set(null);
  if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
    scale = mDrawableRect.height() / (float) mBitmapHeight;
    dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
  } else {
    scale = mDrawableRect.width() / (float) mBitmapWidth;
    dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
  }
  mShaderMatrix.setScale(scale, scale);
  mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top);
  mBitmapShader.setLocalMatrix(mShaderMatrix);
}
origin: wasabeef/glide-transformations

@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
              @NonNull Bitmap toTransform, int outWidth, int outHeight) {
 int width = toTransform.getWidth();
 int height = toTransform.getHeight();
 Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
 bitmap.setHasAlpha(true);
 Canvas canvas = new Canvas(bitmap);
 Paint paint = new Paint();
 paint.setAntiAlias(true);
 paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
 drawRoundRect(canvas, paint, width, height);
 return bitmap;
}
origin: vinc3m1/RoundedImageView

@Override
public void draw(@NonNull Canvas canvas) {
 if (mRebuildShader) {
  BitmapShader bitmapShader = new BitmapShader(mBitmap, mTileModeX, mTileModeY);
  if (mTileModeX == Shader.TileMode.CLAMP && mTileModeY == Shader.TileMode.CLAMP) {
   bitmapShader.setLocalMatrix(mShaderMatrix);
origin: HotBitmapGG/bilibili-android-client

  private void updateShaderMatrix() {
    float scale;
    float dx = 0;
    float dy = 0;
    mShaderMatrix.set(null);
    if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
      scale = mDrawableRect.height() / (float) mBitmapHeight;
      dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
    } else {
      scale = mDrawableRect.width() / (float) mBitmapWidth;
      dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
    }
    mShaderMatrix.setScale(scale, scale);
    mShaderMatrix.postTranslate((int) (dx + 0.5f) + mDrawableRect.left, (int) (dy + 0.5f) + mDrawableRect.top);
    mBitmapShader.setLocalMatrix(mShaderMatrix);
  }
}
android.graphicsBitmapShader

Most used methods

  • <init>
  • setLocalMatrix
  • getLocalMatrix

Popular in Java

  • Reading from database using SQL prepared statement
  • getContentResolver (Context)
  • setRequestProperty (URLConnection)
  • findViewById (Activity)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • JFileChooser (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now