本文整理匯總了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;
}