本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
}
示例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);
}
示例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;
}