当前位置: 首页>>代码示例>>Java>>正文


Java BitmapShader类代码示例

本文整理汇总了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;
}
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:20,代码来源:GlideCircleTransform.java

示例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;
}
 
开发者ID:WGPlaner,项目名称:wg_planer,代码行数:27,代码来源:CircularImageView.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:FlikerProgressBar.java

示例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;
}
 
开发者ID:ynztlxdeai,项目名称:TextReader,代码行数:22,代码来源:GlideCircleTransform.java

示例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;
}
 
开发者ID:snowwolf10285,项目名称:PicShow-zhaipin,代码行数:24,代码来源:CircleTransform.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:GlideTransform.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:GlideCircleTransform.java

示例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;
}
 
开发者ID:Assassinss,项目名称:Moment,代码行数:24,代码来源:CircleTransform.java

示例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);

    }
 
开发者ID:penghuanliang,项目名称:Rxjava2.0Demo,代码行数:19,代码来源:DrawTextView.java

示例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;
}
 
开发者ID:devilist,项目名称:SnakeViewMaker,代码行数:24,代码来源:RoundTransformation.java

示例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);
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:23,代码来源:SelectableRoundedImageView.java

示例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));
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:20,代码来源:WorkspaceGridRenderer.java

示例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;
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:27,代码来源:CircleTransform.java

示例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;
}
 
开发者ID:YunzhanghuOpen,项目名称:redpacketui-open,代码行数:24,代码来源:CircleTransform.java

示例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;
}
 
开发者ID:picopalette,项目名称:event-me,代码行数:24,代码来源:CircleTransform.java


注:本文中的android.graphics.BitmapShader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。