Codota Logo
BitmapShader.setLocalMatrix
Code IndexAdd Codota to your IDE (free)

How to use
setLocalMatrix
method
in
android.graphics.BitmapShader

Best Java code snippets using android.graphics.BitmapShader.setLocalMatrix (Showing top 20 results out of 1,152)

  • Common ways to obtain BitmapShader
private void myMethod () {
BitmapShader b =
  • Codota IconBitmap bitmap;Shader.TileMode tileX;new BitmapShader(bitmap, tileX, tileX)
  • Smart code suggestions by Codota
}
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: 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: 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: 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: 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: 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: 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: 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: 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);
  }
}
origin: lygttpod/SuperTextView

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: 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.exactCenterX()  - mBitmap.getWidth() * scale / 2, bounds.exactCenterY() - mBitmap.getHeight() * scale / 2);
  mBitmapShader.setLocalMatrix(mMatrix);
}
origin: iMeiji/Toutiao

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: GitLqr/LQRWeChat

private void updateShaderMatrix() {
  float scale;
  float dx = 0;
  float dy = 0;
  mShaderMatrix = new Matrix();
  mShaderMatrix.set(null);
  mDrawableRect = new Rect(0, 0, getRight() - getLeft(), getBottom()
      - getTop());
  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), (int) (dy + 0.5f));
  mBitmapShader.setLocalMatrix(mShaderMatrix);
}
origin: Bearded-Hen/Android-Bootstrap

matrix.postTranslate((dx + 0.5f), (dy + 0.5f));
imageShader.setLocalMatrix(matrix);
imageRectF.set(0, 0, viewWidth, viewHeight);
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: 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: ZieIony/Carbon

Matrix matrix = new Matrix();
matrix.postTranslate(bounds.left, bounds.top);
checkedShader.setLocalMatrix(matrix);
origin: vinc3m1/RoundedImageView

BitmapShader bitmapShader = new BitmapShader(mBitmap, mTileModeX, mTileModeY);
if (mTileModeX == Shader.TileMode.CLAMP && mTileModeY == Shader.TileMode.CLAMP) {
 bitmapShader.setLocalMatrix(mShaderMatrix);
origin: ZieIony/Carbon

final Rect bounds = getBounds();
mMaskMatrix.setTranslate(bounds.left - x, bounds.top - y);
mMaskShader.setLocalMatrix(mMaskMatrix);
origin: weexteam/weex-hackernews

private static void updateShaderAndSize(@NonNull ImageView.ScaleType scaleType, int vWidth, int vHeight, ImageDrawable imageDrawable, BitmapShader bitmapShader) {
 Matrix matrix = createShaderMatrix(scaleType, vWidth, vHeight,
                   imageDrawable.bitmapWidth,
                   imageDrawable.bitmapHeight);
 int intrinsicWidth = vWidth, intrinsicHeight = vHeight;
 if (scaleType == ImageView.ScaleType.FIT_CENTER) {
  RectF bitmapRect = new RectF(0, 0, imageDrawable.bitmapWidth, imageDrawable.bitmapHeight), contentRect = new RectF();
  matrix.mapRect(contentRect, bitmapRect);
  intrinsicWidth = (int) contentRect.width();
  intrinsicHeight = (int) contentRect.height();
  matrix = createShaderMatrix(scaleType, intrinsicWidth, intrinsicHeight, imageDrawable
    .bitmapWidth, imageDrawable.bitmapHeight);
 }
 imageDrawable.setIntrinsicWidth(intrinsicWidth);
 imageDrawable.setIntrinsicHeight(intrinsicHeight);
 bitmapShader.setLocalMatrix(matrix);
}
android.graphicsBitmapShadersetLocalMatrix

Popular methods of BitmapShader

  • <init>
  • getLocalMatrix

Popular in Java

  • Reactive rest calls using spring rest template
  • getResourceAsStream (ClassLoader)
  • getApplicationContext (Context)
  • orElseThrow (Optional)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • HashSet (java.util)
    This class implements the Set interface, backed by a hash table (actually a HashMap instance). It m
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • TreeSet (java.util)
    A NavigableSet implementation based on a TreeMap. The elements are ordered using their Comparable, o
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now