当前位置: 首页>>代码示例>>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;未经允许,请勿转载。