當前位置: 首頁>>代碼示例>>Java>>正文


Java BitmapShader.setLocalMatrix方法代碼示例

本文整理匯總了Java中android.graphics.BitmapShader.setLocalMatrix方法的典型用法代碼示例。如果您正苦於以下問題:Java BitmapShader.setLocalMatrix方法的具體用法?Java BitmapShader.setLocalMatrix怎麽用?Java BitmapShader.setLocalMatrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.BitmapShader的用法示例。


在下文中一共展示了BitmapShader.setLocalMatrix方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupBitmap

import android.graphics.BitmapShader; //導入方法依賴的package包/類
private void setupBitmap(ImageView imageView, float width, float height) {
    Drawable drawable = imageView.getDrawable();
    if (drawable == null) {
        return;
    }
    try {
        bitmap = (drawable instanceof BitmapDrawable) ?
                ((BitmapDrawable) drawable).getBitmap() :
                Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                        drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (bitmap == null) {
        imageView.invalidate();
        return;
    }
    paint = new Paint(ANTI_ALIAS_FLAG);
    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    paint.setShader(bitmapShader);
    if (imageView.getScaleType() != ImageView.ScaleType.CENTER_CROP && imageView.getScaleType() != ImageView.ScaleType.FIT_XY) {
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    }
    bitmapShader.setLocalMatrix(setUpScaleType(bitmap, imageView, width, height));
    imageView.invalidate();
}
 
開發者ID:akshay2211,項目名稱:Oblique,代碼行數:27,代碼來源:ObliqueView.java

示例2: RoundedDrawable

import android.graphics.BitmapShader; //導入方法依賴的package包/類
public RoundedDrawable(Bitmap bitmap) {

        mBitmapWidth = bitmap.getWidth();
        mBitmapHeight = bitmap.getHeight();
        mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

        mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mBitmapShader.setLocalMatrix(mShaderMatrix);

        mBitmapPaint = new Paint();
        mBitmapPaint.setStyle(Paint.Style.FILL);
        mBitmapPaint.setAntiAlias(true);
        mBitmapPaint.setShader(mBitmapShader);

        mBorderPaint = new Paint();
        mBorderPaint.setStyle(Paint.Style.STROKE);
        mBorderPaint.setAntiAlias(true);
        mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
        mBorderPaint.setStrokeWidth(mBorderWidth);
    }
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:21,代碼來源:RoundedDrawable.java

示例3: updateShader

import android.graphics.BitmapShader; //導入方法依賴的package包/類
private void updateShader() {
    if (image == null)
        return;

    // Crop Center Image
    image = cropBitmap(image);

    // Create Shader
    BitmapShader shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    // Center Image in Shader
    Matrix matrix = new Matrix();
    matrix.setScale((float) canvasSize / (float) image.getWidth(), (float) canvasSize / (float) image.getHeight());
    shader.setLocalMatrix(matrix);

    // Set Shader in Paint
    paint.setShader(shader);
}
 
開發者ID:afiqiqmal,項目名稱:MVP-Android,代碼行數:19,代碼來源:CircleImageView.java

示例4: RoundedDrawable

import android.graphics.BitmapShader; //導入方法依賴的package包/類
public RoundedDrawable(Bitmap bitmap)
{

	mBitmapWidth = bitmap.getWidth();
	mBitmapHeight = bitmap.getHeight();
	mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

	mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
	mBitmapShader.setLocalMatrix(mShaderMatrix);

	mBitmapPaint = new Paint();
	mBitmapPaint.setStyle(Paint.Style.FILL);
	mBitmapPaint.setAntiAlias(true);
	mBitmapPaint.setShader(mBitmapShader);

	mBorderPaint = new Paint();
	mBorderPaint.setStyle(Paint.Style.STROKE);
	mBorderPaint.setAntiAlias(true);
	mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
	mBorderPaint.setStrokeWidth(mBorderWidth);
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:22,代碼來源:RoundedDrawable.java

示例5: onSizeChanged

import android.graphics.BitmapShader; //導入方法依賴的package包/類
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap, w, h, true);
    mRippleScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap,
            (int) (w * RIPPLE_SCALE_FACTOR), (int) (h * RIPPLE_SCALE_FACTOR), true);
    int width1 = mScaledBitmap.getWidth();
    int height1 = mScaledBitmap.getHeight();
    int width2 = mRippleScaledBitmap.getWidth();
    int height2 = mRippleScaledBitmap.getHeight();
    mDisW = Math.abs(width1 - width2) / 2;
    mDisH = Math.abs(height1 - height2) / 2;//算出兩圖中點相聚的距離,就是放大後需要矯正的位移距離
    mOriBitmap.recycle();
    mOriBitmap = null;
    //這裏的模式無所謂,因為在屏幕外看不到
    mBitmapShader = new BitmapShader(mRippleScaledBitmap,
            Shader.TileMode.MIRROR,//這裏的模式無所謂,因為在屏幕外看不到
            Shader.TileMode.MIRROR);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-mDisW, -mDisH);
    mBitmapShader.setLocalMatrix(matrix);
}
 
開發者ID:halohoop,項目名稱:AndroidDigIn,代碼行數:23,代碼來源:RadialGradientRippleView.java

示例6: updateShaderAndSize

import android.graphics.BitmapShader; //導入方法依賴的package包/類
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);
}
 
開發者ID:erguotou520,項目名稱:weex-uikit,代碼行數:18,代碼來源:ImageDrawable.java

示例7: setIcon

import android.graphics.BitmapShader; //導入方法依賴的package包/類
public void setIcon(Bitmap bitmap) {
    if (bitmap != null) {
        mIconWidth = bitmap.getWidth();
        mIconHeight = bitmap.getHeight();
        mIconShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mIconShader.setLocalMatrix(mIconMatrix);
        mIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mIconPaint.setShader(mIconShader);
        mIconPaint.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));

        invalidateSelf();
    } else {
        mIconWidth = 0;
        mIconHeight = 0;
        mIconShader = null;
        mIconMatrix = null;
        mIconPaint = null;
    }
}
 
開發者ID:dewarder,項目名稱:HoldingButton,代碼行數:20,代碼來源:HoldingDrawable.java

示例8: setCancelIcon

import android.graphics.BitmapShader; //導入方法依賴的package包/類
public void setCancelIcon(Bitmap bitmap) {
    if (bitmap != null) {
        mCancelIconWidth = bitmap.getWidth();
        mCancelIconHeight = bitmap.getHeight();
        mCancelIconShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mCancelIconShader.setLocalMatrix(mCancelIconMatrix);
        mCancelIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mCancelIconPaint.setShader(mCancelIconShader);
        mCancelIconPaint.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));

        invalidateSelf();
    } else {
        mCancelIconWidth = 0;
        mCancelIconHeight = 0;
        mCancelIconMatrix = null;
        mCancelIconPaint = null;
    }
}
 
開發者ID:dewarder,項目名稱:HoldingButton,代碼行數:19,代碼來源:HoldingDrawable.java

示例9: setBitmapShader

import android.graphics.BitmapShader; //導入方法依賴的package包/類
/**
 * 設置BitmapShader
 */
private void setBitmapShader() {
    Drawable drawable = getDrawable();
    if (null == drawable) {
        return;
    }
    Bitmap bitmap = drawableToBitmap(drawable);
    // 將bitmap作為著色器來創建一個BitmapShader
    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    float scale = 1.0f;
    if (mType == TYPE_CIRCLE) {
        // 拿到bitmap寬或高的小值
        int bSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
        scale = mWidth * 1.0f / bSize;

    } else if (mType == TYPE_ROUND || mType == TYPE_OVAL) {
        // 如果圖片的寬或者高與view的寬高不匹配,計算出需要縮放的比例;縮放後的圖片的寬高,一定要大於我們view的寬高;所以我們這裏取大值;
        scale = Math.max(getWidth() * 1.0f / bitmap.getWidth(), getHeight() * 1.0f / bitmap.getHeight());
    }
    // shader的變換矩陣,我們這裏主要用於放大或者縮小
    mMatrix.setScale(scale, scale);
    // 設置變換矩陣
    mBitmapShader.setLocalMatrix(mMatrix);
    mPaint.setShader(mBitmapShader);

}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:29,代碼來源:ImageViewRadius.java

示例10: setupBitmapPaint

import android.graphics.BitmapShader; //導入方法依賴的package包/類
protected boolean setupBitmapPaint() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return false;
    }

    Bitmap bitmap = getBitmapFromDrawable(drawable);
    if(bitmap == null){
        return false;
    }

    BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    bitmapShader.setLocalMatrix(getImageMatrix());
    mBitmapPaint.setShader(bitmapShader);
    return true;
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:17,代碼來源:RoundedImageView.java

示例11: updateBitmapShader

import android.graphics.BitmapShader; //導入方法依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:CircularImageView.java

示例12: toRound

import android.graphics.BitmapShader; //導入方法依賴的package包/類
/**
 * 轉為圓形圖片
 *
 * @param src         源圖片
 * @param recycle     是否回收
 * @param borderSize  邊框尺寸
 * @param borderColor 邊框顏色
 * @return 圓形圖片
 */
public static Bitmap toRound(final Bitmap src,
                             @IntRange(from = 0) int borderSize,
                             @ColorInt int borderColor,
                             final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int size = Math.min(width, height);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    float center = size / 2f;
    RectF rectF = new RectF(0, 0, width, height);
    rectF.inset((width - size) / 2f, (height - size) / 2f);
    Matrix matrix = new Matrix();
    matrix.setTranslate(rectF.left, rectF.top);
    matrix.preScale((float) size / width, (float) size / height);
    BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    Canvas canvas = new Canvas(ret);
    canvas.drawRoundRect(rectF, center, center, paint);
    if (borderSize > 0) {
        paint.setShader(null);
        paint.setColor(borderColor);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderSize);
        float radius = center - borderSize / 2f;
        canvas.drawCircle(width / 2f, height / 2f, radius, paint);
    }
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:42,代碼來源:ImageUtils.java

示例13: draw

import android.graphics.BitmapShader; //導入方法依賴的package包/類
@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);
    }
    mBitmapPaint.setShader(bitmapShader);
    mRebuildShader = false;
  }

  if (mOval) {
    if (mBorderWidth > 0) {
      canvas.drawOval(mDrawableRect, mBitmapPaint);
      canvas.drawOval(mBorderRect, mBorderPaint);
    } else {
      canvas.drawOval(mDrawableRect, mBitmapPaint);
    }
  } else {
    if (any(mCornersRounded)) {
      float radius = mCornerRadius;
      if (mBorderWidth > 0) {
        canvas.drawRoundRect(mDrawableRect, radius, radius, mBitmapPaint);
        canvas.drawRoundRect(mBorderRect, radius, radius, mBorderPaint);
        redrawBitmapForSquareCorners(canvas);
        redrawBorderForSquareCorners(canvas);
      } else {
        canvas.drawRoundRect(mDrawableRect, radius, radius, mBitmapPaint);
        redrawBitmapForSquareCorners(canvas);
      }
    } else {
      canvas.drawRect(mDrawableRect, mBitmapPaint);
      if (mBorderWidth > 0) {
        canvas.drawRect(mBorderRect, mBorderPaint);
      }
    }
  }
}
 
開發者ID:jrvansuita,項目名稱:MaterialAbout,代碼行數:39,代碼來源:RoundedDrawable.java

示例14: studyBitmapShader

import android.graphics.BitmapShader; //導入方法依賴的package包/類
/**
     * 位圖圖像渲染
     * @param canvas
     */
    private void studyBitmapShader(Canvas canvas) {
        //創建BitmapShader
        //其中TileMode.MIRROR x方向鏡像  TileMode.REPEAT y方向重複
        mBitmapShader = new BitmapShader(mBitMap, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT);

        //創建矩陣   來縮放圖片
        Matrix matrix = new Matrix();
        matrix.setScale(0.2f,0.2f);
        mBitmapShader.setLocalMatrix(matrix);

        mPaint.setAntiAlias(true);
        mPaint.setShader(mBitmapShader);

        //畫圓形的圖片
//        canvas.drawCircle(mBitMap.getWidth()/2,mBitMap.getHeight()/2,300,mPaint);

        //畫矩形的圖片
//        Rect rect = new Rect(0,0,600,600);
//        canvas.drawRect(rect,mPaint);
//
        //畫橢圓的圖片
//        RectF rectf = new RectF(0,0,400,300);
//
//        canvas.drawOval(rectf,mPaint);

        //用shapeDrawable 實現圓形圖片
        ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
        shapeDrawable.getPaint().setShader(mBitmapShader);
        shapeDrawable.setBounds(0,0,400,400);
        shapeDrawable.draw(canvas);

    }
 
開發者ID:fanxiaole,項目名稱:androidShader_rippleView_radarView,代碼行數:37,代碼來源:MyGradientView.java

示例15: transform

import android.graphics.BitmapShader; //導入方法依賴的package包/類
@Override public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());

  int width = (source.getWidth() - size) / 2;
  int height = (source.getHeight() - size) / 2;

  Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader =
      new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  if (width != 0 || height != 0) {
    // source isn't square, move viewport to center
    Matrix matrix = new Matrix();
    matrix.setTranslate(-width, -height);
    shader.setLocalMatrix(matrix);
  }
  paint.setShader(shader);
  paint.setAntiAlias(true);

  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);

  source.recycle();

  return bitmap;
}
 
開發者ID:open-android,項目名稱:Picasso-transformations,代碼行數:29,代碼來源:CropCircleTransformation.java


注:本文中的android.graphics.BitmapShader.setLocalMatrix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。