本文整理汇总了Java中android.graphics.BitmapShader类的典型用法代码示例。如果您正苦于以下问题:Java BitmapShader类的具体用法?Java BitmapShader怎么用?Java BitmapShader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitmapShader类属于android.graphics包,在下文中一共展示了BitmapShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: circleCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
示例2: updateShaderMatrix
import android.graphics.BitmapShader; //导入依赖的package包/类
private BitmapShader updateShaderMatrix(BitmapShader shader) {
float scale;
float dx = 0;
float dy = 0;
calculateBounds();
Matrix shaderMatrix = new Matrix();
shaderMatrix.set(null);
if (mBitmapWidth * mBoundsRect.height() > mBitmapHeight * mBoundsRect.width()) {
scale = mBoundsRect.height() / (float) mBitmapHeight;
dx = (mBoundsRect.width() - mBitmapWidth * scale) * 0.5f;
} else {
scale = mBoundsRect.width() / (float) mBitmapWidth;
dy = (mBoundsRect.height() - mBitmapHeight * scale) * 0.5f;
}
shaderMatrix.setScale(scale, scale);
shaderMatrix.postTranslate((int)(dx + 0.5f) + mBoundsRect.left, (int)(dy + 0.5f) + mBoundsRect.top);
shader.setLocalMatrix(shaderMatrix);
return shader;
}
示例3: drawProgress
import android.graphics.BitmapShader; //导入依赖的package包/类
/**
* 进度
*/
private void drawProgress(Canvas canvas) {
pgPaint.setColor(progressColor);
float right = (progress / maxProgress) * getMeasuredWidth();
pgCanvas.save(Canvas.CLIP_SAVE_FLAG);
pgCanvas.clipRect(0, 0, right, getMeasuredHeight());
pgCanvas.drawColor(progressColor);
pgCanvas.restore();
if(!isStop){
pgPaint.setXfermode(xfermode);
pgCanvas.drawBitmap(flikerBitmap, flickerLeft, 0, pgPaint);
pgPaint.setXfermode(null);
}
//控制显示区域
bitmapShader = new BitmapShader(pgBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
pgPaint.setShader(bitmapShader);
canvas.drawRoundRect(bgRectf, radius, radius, pgPaint);
}
示例4: circleCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null)
return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP,
BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
示例5: circleCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
示例6: roundCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
canvas.drawRoundRect(rectF, radius, radius, paint);
return result;
}
示例7: circleCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
示例8: circleCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squared.recycle();
return result;
}
示例9: initPaint
import android.graphics.BitmapShader; //导入依赖的package包/类
private void initPaint() {
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, dm);
mPaint = new Paint();
mPaint.setColor(Color.RED);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(1);
mPaint.setTextSize(35);
mPaint.setColorFilter(new ColorFilter());
// mPaint.setStyle(Paint.Style.STROKE);
mPath = new Path();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bg1);
bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.bg2);
bitmapShader1 = new BitmapShader(bitmap1, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
shader = new ComposeShader(bitmapShader, bitmapShader1, PorterDuff.Mode.SRC_OVER);
}
示例10: transform
import android.graphics.BitmapShader; //导入依赖的package包/类
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
if (null == toTransform)
return null;
// outWidth is the width of the target ImageView,and the same to outHeight
// all the ori bitmaps loaded may have different size, in order to the clipped
// the bitmaps have the same size and shape,we use the target ImageView's size
// to create bitmaps
updateDrawBound(toTransform.getWidth(), toTransform.getHeight(), outWidth, outHeight);
Bitmap bitmap = pool.get(drawWidth, drawHeight, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(drawWidth, drawHeight, Bitmap.Config.ARGB_8888);
}
bitmap.setHasAlpha(true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint);
return bitmap;
}
示例11: SelectableRoundedCornerDrawable
import android.graphics.BitmapShader; //导入依赖的package包/类
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
mbBitmap = bitmap;
mmBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
if (bitmap != null) {
mmBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
mmBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
} else {
mmBitmapWidth = mmBitmapHeight = -1;
}
mmBitmapRect.set(0, 0, mmBitmapWidth, mmBitmapHeight);
mmBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mmBitmapPaint.setStyle(Paint.Style.FILL);
mmBitmapPaint.setShader(mmBitmapShader);
mmBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mmBorderPaint.setStyle(Paint.Style.STROKE);
mmBorderPaint.setColor(mmBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
mmBorderPaint.setStrokeWidth(mmBorderWidth);
}
示例12: updateGridBitmap
import android.graphics.BitmapShader; //导入依赖的package包/类
/**
* Using the current view scale, create a bitmap tiling shader to render the workspace grid.
*/
void updateGridBitmap(float viewScale) {
int gridSpacing = (int) (GRID_SPACING * viewScale);
// For some reason, reusing the same Bitmap via Bitmap.reconfigure() leads to bad rendering,
// so recycle existing Bitmap and create a new one instead.
if (mGridBitmap != null) {
mGridBitmap.recycle();
}
mGridBitmap = Bitmap.createBitmap(gridSpacing, gridSpacing, Bitmap.Config.ARGB_8888);
Canvas bitmapCanvas = new Canvas(mGridBitmap);
bitmapCanvas.drawCircle(GRID_RADIUS, GRID_RADIUS, GRID_RADIUS, mCirclePaint);
mGridPaint.setShader(
new BitmapShader(mGridBitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
}
示例13: transform
import android.graphics.BitmapShader; //导入依赖的package包/类
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
示例14: circleCrop
import android.graphics.BitmapShader; //导入依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
float r = size / 2f;
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setColor(Color.parseColor("#F9F9F9"));
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(r, r, r, paint);
paint.reset();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
canvas.drawCircle(r, r, r, paint);
return result;
}
示例15: transform
import android.graphics.BitmapShader; //导入依赖的package包/类
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
if (toTransform == null) return null;
int size = Math.min(toTransform.getWidth(), toTransform.getHeight());
int x = (toTransform.getWidth() - size) / 2;
int y = (toTransform.getHeight() - size) / 2;
Bitmap squared = Bitmap.createBitmap(toTransform, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}