當前位置: 首頁>>代碼示例>>Java>>正文


Java Shader類代碼示例

本文整理匯總了Java中android.graphics.Shader的典型用法代碼示例。如果您正苦於以下問題:Java Shader類的具體用法?Java Shader怎麽用?Java Shader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Shader類屬於android.graphics包,在下文中一共展示了Shader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupBitmap

import android.graphics.Shader; //導入依賴的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();
}
 
開發者ID:akshay2211,項目名稱:Oblique,代碼行數:27,代碼來源:ObliqueView.java

示例2: resetLinearGradient

import android.graphics.Shader; //導入依賴的package包/類
private void resetLinearGradient() {

        // our gradient is a simple linear gradient from textColor to reflectionColor. its axis is at the center
        // when it's outside of the view, the outer color (textColor) will be repeated (Shader.TileMode.CLAMP)
        // initially, the linear gradient is positioned on the left side of the view
        linearGradient = new LinearGradient(-view.getWidth(), 0, 0, 0,
                new int[]{
                        primaryColor,
                        reflectionColor,
                        primaryColor,
                },
                new float[]{
                        0,
                        0.5f,
                        1
                },
                Shader.TileMode.CLAMP
        );

        paint.setShader(linearGradient);
    }
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:22,代碼來源:ShimmerViewHelper.java

示例3: updateColorDependant

import android.graphics.Shader; //導入依賴的package包/類
protected void updateColorDependant(boolean hsvChanged, boolean hueChanged){
    if (hueChanged) {
        Shader base = new LinearGradient(A.x, A.y, (B.x + C.x) / 2, (B.y + C.y) / 2,
                Color.HSVToColor(new float[]{mColor.hue(), 1, 1}), Color.BLACK, Shader.TileMode.CLAMP);
        Shader light = new LinearGradient((A.x + C.x) / 2, (A.y + C.y) / 2, B.x, B.y,
                Color.BLACK, Color.WHITE, Shader.TileMode.CLAMP);
        Shader both = new ComposeShader(base, light, PorterDuff.Mode.ADD);
        paint.setShader(both);
    }
    if (hsvChanged) {
        dotPaint.setColor(mColor.inverted().rgb());
        dot = new PointF(
                C.x + (B.x - C.x + (A.x - B.x) * mColor.sat()) * mColor.val(),
                C.y + (B.y - C.y + (A.y - B.y) * mColor.sat()) * mColor.val());
    }
}
 
開發者ID:eltos,項目名稱:SimpleDialogFragments,代碼行數:17,代碼來源:ColorWheelView.java

示例4: draw

import android.graphics.Shader; //導入依賴的package包/類
@Override
public void draw(Canvas canvas) {
    Rect b = getBounds();
    int height = b.height();
    int width = b.width();

    Paint valuePaint = new Paint();
    valuePaint.setShader(
            new LinearGradient(0, mInset, 0, height - mInset,
                    Color.WHITE, Color.BLACK, Shader.TileMode.CLAMP)
    );

    float hsv[] = {mHue, 1.0f, 1.0f};
    int pureHue = Color.HSVToColor(hsv);
    Paint saturationPaint = new Paint();
    saturationPaint.setShader(
            new LinearGradient(mInset, 0, width - mInset, 0,
                    Color.WHITE, pureHue, Shader.TileMode.CLAMP)
    );
    saturationPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));

    canvas.drawRect(b, valuePaint);
    canvas.drawRect(b, saturationPaint);
}
 
開發者ID:google,項目名稱:spline,代碼行數:25,代碼來源:SaturationValueDrawable.java

示例5: BubbleDrawable

import android.graphics.Shader; //導入依賴的package包/類
public BubbleDrawable(Builder builder) {
    triangleWidth = builder.triangleWidth;
    triangleHeight = builder.triangleHeight;
    offset = builder.offset;
    radius = builder.radius;
    orientation = builder.orientation;
    bitmap = builder.bitmap;
    borderWidth = builder.borderWidth;
    centerArrow = builder.centerArrow;
    shadowRadius = builder.shadowRadius;
    shadowColor = builder.shadowColor;

    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeCap(Paint.Cap.ROUND);
    borderPaint.setColor(builder.borderColor);

    leftTopRadiusRect = new RectF();
    rightBottomRadiusRect = new RectF();
    leftBottomRadiusRect = new RectF();
    rightTopRadiusRect = new RectF();

    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    bitmapPaint.setShader(bitmapShader);
}
 
開發者ID:leochuan,項目名稱:BubbleView,代碼行數:25,代碼來源:BubbleDrawable.java

示例6: setColor

import android.graphics.Shader; //導入依賴的package包/類
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if(mOrientation) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	}        else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}
	
	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0,
			x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
			Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if(mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:32,代碼來源:SVBar.java

示例7: transform

import android.graphics.Shader; //導入依賴的package包/類
@Override public Bitmap transform(Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    drawRoundRect(canvas, paint, width, height);
    source.recycle();

    return bitmap;
  }
 
開發者ID:open-android,項目名稱:Picasso-transformations,代碼行數:17,代碼來源:RoundedCornersTransformation.java

示例8: setupView

import android.graphics.Shader; //導入依賴的package包/類
private void setupView() {
    if (!mReady) {
        mSetupPending = true;
        return;
    }
    if (mBitmap == null) return;
    mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setAntiAlias(true);
    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();
    mBorderRect.set(0, 0, getWidth(), getHeight());
    mDrawableRect.set(mBorderRect);
    mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
    updateShaderMatrix();
    invalidate();
}
 
開發者ID:shenhuanet,項目名稱:OpenEyesReading-android,代碼行數:20,代碼來源:CircleImageView.java

示例9: getSourceMaskBitmap

import android.graphics.Shader; //導入依賴的package包/類
private Bitmap getSourceMaskBitmap() {
    if (sourceMaskBitmap != null) {
        return sourceMaskBitmap;
    }

    int width = maskRect.width();
    int height = getHeight();

    final int edgeColor = reduceColorAlphaValueToZero(shimmerColor);
    LinearGradient gradient = new LinearGradient(
            -maskRect.left, 0,
            width + maskRect.left, 0,
            new int[]{edgeColor, shimmerColor, shimmerColor, edgeColor},
            getGradientColorDistribution(),
            Shader.TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(gradient);

    sourceMaskBitmap = createBitmap(width, height);
    Canvas canvas = new Canvas(sourceMaskBitmap);
    canvas.rotate(shimmerAngle, width / 2, height / 2);
    canvas.drawRect(-maskRect.left, maskRect.top, width + maskRect.left, maskRect.bottom, paint);

    return sourceMaskBitmap;
}
 
開發者ID:team-supercharge,項目名稱:ShimmerLayout,代碼行數:26,代碼來源:ShimmerLayout.java

示例10: setColor

import android.graphics.Shader; //導入依賴的package包/類
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
	int x1, y1;
	if (mOrientation) {
		x1 = (mBarLength + mBarPointerHaloRadius);
		y1 = mBarThickness;
	} else {
		x1 = mBarThickness;
		y1 = (mBarLength + mBarPointerHaloRadius);
	}

	Color.colorToHSV(color, mHSVColor);
	shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1,
			new int[] { Color.WHITE, color, Color.BLACK }, null,
			Shader.TileMode.CLAMP);
	mBarPaint.setShader(shader);
	calculateColor(mBarPointerPosition);
	mBarPointerPaint.setColor(mColor);
	if (mPicker != null) {
		mPicker.setNewCenterColor(mColor);
		if (mPicker.hasOpacityBar())
			mPicker.changeOpacityBarColor(mColor);
	}
	invalidate();
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:32,代碼來源:SVBar.java

示例11: getFotoBitmap

import android.graphics.Shader; //導入依賴的package包/類
public Bitmap getFotoBitmap(Context context) {

        Bitmap image;

        if (this.foto != null) {
            image = BitmapFactory.decodeByteArray(this.foto, 0, this.foto.length);
        } else {
            image = BitmapFactory.decodeResource(context.getResources(), R.drawable.pessoa_foto_default);
        }

        Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
        Canvas canvas = new Canvas(imageRounded);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), image.getWidth() / 2, image.getWidth() / 2, paint);// Round Image Corner 100 100 100 100

        return imageRounded;
    }
 
開發者ID:secompufscar,項目名稱:app_secompufscar,代碼行數:20,代碼來源:Pessoa.java

示例12: setCancelIcon

import android.graphics.Shader; //導入依賴的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;
    }
}
 
開發者ID:dewarder,項目名稱:HoldingButton,代碼行數:19,代碼來源:HoldingDrawable.java

示例13: getImageRound

import android.graphics.Shader; //導入依賴的package包/類
public static Bitmap getImageRound(byte[] imageByte) {

        Bitmap image;

        image = BitmapFactory.decodeByteArray(imageByte, 0, imageByte.length);

        //TODO: Verificar se o formato da imagem está correto;
        Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
        Canvas canvas = new Canvas(imageRounded);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), image.getWidth() / 2, image.getWidth() / 2, paint);// Round Image Corner 100 100 100 100

        return imageRounded;
    }
 
開發者ID:secompufscar,項目名稱:app_secompufscar,代碼行數:17,代碼來源:Instagram.java

示例14: updateShader

import android.graphics.Shader; //導入依賴的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);
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:19,代碼來源:CircleImageView.java

示例15: onDraw

import android.graphics.Shader; //導入依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    onDrawReady = true;
    imageRenderedAtLeastOnce = true;
    if (delayedZoomVariables != null) {
        setZoom(delayedZoomVariables.scale, delayedZoomVariables.focusX, delayedZoomVariables.focusY, delayedZoomVariables.scaleType);
        delayedZoomVariables = null;
    }
    super.onDraw(canvas);
    if (!zooming) {
        buildDrawingCache();
    } else {

        bitmap = getDrawingCache();
        shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

        paint = new Paint();
        paint.setShader(shader);
        eMatrix.reset();
        eMatrix.postScale(2f, 2f, zoomPos.x, zoomPos.y);
        paint.getShader().setLocalMatrix(eMatrix);
        canvas.drawCircle(zoomPos.x, zoomPos.y, sizeOfMagnifier, paint);
    }
}
 
開發者ID:geeknat,項目名稱:spinify_android,代碼行數:25,代碼來源:TouchImageView.java


注:本文中的android.graphics.Shader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。