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;
}
java类android.graphics.BitmapShader的实例源码
GlideCircleTransform.java 文件源码
项目:ClouldReader
阅读 43
收藏 0
点赞 0
评论 0
CircularImageView.java 文件源码
项目:wg_planer
阅读 32
收藏 0
点赞 0
评论 0
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;
}
FlikerProgressBar.java 文件源码
项目:GitHub
阅读 38
收藏 0
点赞 0
评论 0
/**
* 进度
*/
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);
}
GlideCircleTransform.java 文件源码
项目:GitHub
阅读 35
收藏 0
点赞 0
评论 0
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;
}
GlideCircleTransform.java 文件源码
项目:TextReader
阅读 35
收藏 0
点赞 0
评论 0
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;
}
CircleTransform.java 文件源码
项目:PicShow-zhaipin
阅读 43
收藏 0
点赞 0
评论 0
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;
}
GlideTransform.java 文件源码
项目:GitHub
阅读 32
收藏 0
点赞 0
评论 0
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;
}
GlideUtil.java 文件源码
项目:lrs_android
阅读 41
收藏 0
点赞 0
评论 0
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;
}
GlideCircleTransform.java 文件源码
项目:GitHub
阅读 36
收藏 0
点赞 0
评论 0
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;
}
CircleGlide.java 文件源码
项目:Cook-It-Android-XML-Template
阅读 33
收藏 0
点赞 0
评论 0
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;
}
GlideCircleTransform.java 文件源码
项目:EasyEmoji
阅读 34
收藏 0
点赞 0
评论 0
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;
}
CircleTransform.java 文件源码
项目:Moment
阅读 39
收藏 0
点赞 0
评论 0
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;
}
DrawTextView.java 文件源码
项目:Rxjava2.0Demo
阅读 36
收藏 0
点赞 0
评论 0
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);
}
RoundTransformation.java 文件源码
项目:SnakeViewMaker
阅读 31
收藏 0
点赞 0
评论 0
@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;
}
SelectableRoundedImageView.java 文件源码
项目:BBSSDK-for-Android
阅读 48
收藏 0
点赞 0
评论 0
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);
}
GlideCircleTransfromUtil.java 文件源码
项目:MyFire
阅读 33
收藏 0
点赞 0
评论 0
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;
}
WorkspaceGridRenderer.java 文件源码
项目:Blockly
阅读 36
收藏 0
点赞 0
评论 0
/**
* 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));
}
CircleTransform.java 文件源码
项目:TurboChat
阅读 41
收藏 0
点赞 0
评论 0
@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;
}
CircleTransform.java 文件源码
项目:redpacketui-open
阅读 35
收藏 0
点赞 0
评论 0
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;
}
GlideRoundTransform.java 文件源码
项目:AssistantBySDK
阅读 38
收藏 0
点赞 0
评论 0
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;
}
CircleTransform.java 文件源码
项目:AssistantBySDK
阅读 41
收藏 0
点赞 0
评论 0
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;
}
GlideCircleTransform.java 文件源码
项目:MeiLa_GNN
阅读 27
收藏 0
点赞 0
评论 0
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;
}
CircleTransform.java 文件源码
项目:event-me
阅读 38
收藏 0
点赞 0
评论 0
@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;
}
HoldingDrawable.java 文件源码
项目:HoldingButton
阅读 39
收藏 0
点赞 0
评论 0
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;
}
}
CircularImageView.java 文件源码
项目:RetroMusicPlayer
阅读 27
收藏 0
点赞 0
评论 0
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);
}
ImageDrawable.java 文件源码
项目:ucar-weex-core
阅读 35
收藏 0
点赞 0
评论 0
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);
}
MainActivity.java 文件源码
项目:Paathshala
阅读 40
收藏 0
点赞 0
评论 0
public static Bitmap getCircularBitmapFrom(Bitmap bitmap) {
if (bitmap == null || bitmap.isRecycled()) {
return null;
}
float radius = bitmap.getWidth() > bitmap.getHeight() ? ((float) bitmap
.getHeight()) / 2f : ((float) bitmap.getWidth()) / 2f;
Bitmap canvasBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,
Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Canvas canvas = new Canvas(canvasBitmap);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
radius, paint);
return canvasBitmap;
}
ImageTextView.java 文件源码
项目:Musicoco
阅读 39
收藏 0
点赞 0
评论 0
public ImageTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ImageTextView, defStyleAttr, 0);
mText = "";
mText = array.getString(R.styleable.ImageTextView_text);
mTextSize = array.getDimension(R.styleable.ImageTextView_textSize, 10.0f);
int id = array.getResourceId(R.styleable.ImageTextView_bitmap, R.drawable.default_album);
mBitmap = BitmapFactory.decodeResource(context.getResources(), id);
array.recycle();
paint.setAntiAlias(true);
if (mBitmap != null) {
shader = new BitmapShader(mBitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
}
typeface = Typeface.SERIF;
}
ZQRoundOvalImageView.java 文件源码
项目:decoy
阅读 33
收藏 0
点赞 0
评论 0
/**
* 设置BitmapShader
*/
private void setBitmapShader() {
Drawable drawable = getDrawable();
if (null == drawable) {
return;
}
Bitmap bitmap = drawableToBitmap(drawable);
// 将bitmap作为着色器来创建一个BitmapShader
mBitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, 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);
}
BubbleImageView.java 文件源码
项目:LQRWeChat
阅读 31
收藏 0
点赞 0
评论 0
private void setup() {
if (mBitmap == null) {
return;
}
mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP,
Shader.TileMode.CLAMP);
mBitmapPaint = new Paint();
mBitmapPaint.setAntiAlias(true);
mBitmapPaint.setShader(mBitmapShader);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
updateShaderMatrix();
invalidate();
}