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


Java TileMode.CLAMP屬性代碼示例

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


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

示例1: createColorWheelBitmap

private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:26,代碼來源:ColorPicker.java

示例2: createColorDiscBitmap

private Bitmap createColorDiscBitmap(int radius) {
    int centerColor, edgeColor;
    Bitmap bitmap = Bitmap.createBitmap(2 * radius, 2 * radius, Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    mHSV[0] = 0; mHSV[1] = 1; mHSV[2] = 1;   //red
    SweepGradient sweepGradient = new SweepGradient(radius, radius, getColors(mHSV), null);
    mColorPaint.setShader(sweepGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    mHSV[0] = 0; mHSV[1] = 0; mHSV[2] = 1;   //white
    centerColor = Color.HSVToColor(255, mHSV);
    edgeColor = Color.HSVToColor(0, mHSV);
    RadialGradient radialGradient = new RadialGradient(radius, radius, radius, centerColor, edgeColor, TileMode.CLAMP);
    mColorPaint.setShader(radialGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    return bitmap;
}
 
開發者ID:dftec-es,項目名稱:planetcon,代碼行數:19,代碼來源:ColorPicker.java

示例3: setBitmapShader

/**
 * 設置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);

}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:28,代碼來源:ZQRoundOvalImageView.java

示例4: SelectableRoundedCornerDrawable

public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
    this.mBitmap = bitmap;
    this.mBitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    if (bitmap != null) {
        this.mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
        this.mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
    } else {
        this.mBitmapHeight = -1;
        this.mBitmapWidth = -1;
    }
    this.mBitmapRect.set(0.0f, 0.0f, (float) this.mBitmapWidth, (float) this.mBitmapHeight);
    this.mBitmapPaint = new Paint(1);
    this.mBitmapPaint.setStyle(Style.FILL);
    this.mBitmapPaint.setShader(this.mBitmapShader);
    this.mBorderPaint = new Paint(1);
    this.mBorderPaint.setStyle(Style.STROKE);
    this.mBorderPaint.setColor(this.mBorderColor.getColorForState(getState(), -16777216));
    this.mBorderPaint.setStrokeWidth(this.mBorderWidth);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:SelectableRoundedImageView.java

示例5: setup

private void setup() {
    if (!this.mReady) {
        this.mSetupPending = true;
    } else if (this.mBitmap != null) {
        this.mBitmapShader = new BitmapShader(this.mBitmap, TileMode.CLAMP, TileMode.CLAMP);
        this.mBitmapPaint.setAntiAlias(true);
        this.mBitmapPaint.setShader(this.mBitmapShader);
        this.mBorderPaint.setStyle(Style.STROKE);
        this.mBorderPaint.setAntiAlias(true);
        this.mBorderPaint.setColor(this.mBorderColor);
        this.mBorderPaint.setStrokeWidth((float) this.mBorderWidth);
        this.mBitmapHeight = this.mBitmap.getHeight();
        this.mBitmapWidth = this.mBitmap.getWidth();
        this.mBorderRect.set(0.0f, 0.0f, (float) getWidth(), (float) getHeight());
        this.mBorderRadius = Math.min((this.mBorderRect.height() - ((float) this.mBorderWidth)) / 2.0f, (this.mBorderRect.width() - ((float) this.mBorderWidth)) / 2.0f);
        this.mDrawableRect.set((float) this.mBorderWidth, (float) this.mBorderWidth, this.mBorderRect.width() - ((float) this.mBorderWidth), this.mBorderRect.height() - ((float) this.mBorderWidth));
        this.mDrawableRadius = Math.min(this.mDrawableRect.height() / 2.0f, this.mDrawableRect.width() / 2.0f);
        updateShaderMatrix();
        invalidate();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:CircleImageView.java

示例6: setUpShader

/**
 * 初始化BitmapShader
 */
private void setUpShader()
{
	Drawable drawable = getDrawable();
	if (drawable == null)
	{
		Log.e("view", "ok");
		return;
	}

	Bitmap bmp = drawableToBitamp(drawable);
	// 將bmp作為著色器,就是在指定區域內繪製bmp
	mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
	float scale = 1.0f;
	int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
	scale = getWidth() * 1.0f / bSize;
	// shader的變換矩陣,我們這裏主要用於放大或者縮小
	matrix.setScale(scale, scale);
	// 設置變換矩陣
	mBitmapShader.setLocalMatrix(matrix);
	// 設置shader
	paint.setShader(mBitmapShader);
}
 
開發者ID:liudabao,項目名稱:Evisa,代碼行數:25,代碼來源:CircleView.java

示例7: createReflectionImageWithOrigin

public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap){
	final int reflectionGap = 4;
	int width = bitmap.getWidth();
	int height = bitmap.getHeight();
	Matrix matrix = new Matrix();
	matrix.preScale(1, -1);
	Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix, false);
	Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888);
	Canvas canvas = new Canvas(bitmapWithReflection);
	canvas.drawBitmap(bitmap, 0, 0, null);
	Paint deafalutPaint = new Paint();
	canvas.drawRect(0, height,width,height + reflectionGap, deafalutPaint);
	canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
	Paint paint = new Paint();
	LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight()
			+ reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
	paint.setShader(shader);
	paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

	canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
			+ reflectionGap, paint);
	return bitmapWithReflection;
}
 
開發者ID:javalovercn,項目名稱:j2se_for_android,代碼行數:23,代碼來源:ImageUtil.java

示例8: createReflectionImageWithOrigin

/**
 * 獲得帶倒影的圖片方法
 *
 * @param bitmap 源圖片
 * @return 帶倒影圖片
 */
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = HSBitmapUtil.createBitmap(bitmap, 0,
            height / 2, width, height / 2, matrix, false);
    Bitmap bitmapWithReflection = HSBitmapUtil.createBitmap(width,
            (height + height / 2), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
            0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
            + reflectionGap, paint);
    return bitmapWithReflection;
}
 
開發者ID:WangGanxin,項目名稱:Codebase,代碼行數:31,代碼來源:BitmapUtil.java

示例9: generate

public GVRBitmapTexture generate(GVRContext context, int[] colors, float[] stops) {
    Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Shader shader = new LinearGradient(0,0, 0, HEIGHT,
        colors, stops,
        TileMode.CLAMP);

    Paint paint = new Paint();
    paint.setShader(shader);

    canvas.drawRect(new Rect(0, 0, WIDTH, HEIGHT), paint);

    GVRBitmapTexture texture = new GVRBitmapTexture(context, bitmap);

    return texture;
}
 
開發者ID:mrgrimnevil,項目名稱:browser-vr,代碼行數:17,代碼來源:Background.java

示例10: drawAlphaPanel

private void drawAlphaPanel(Canvas canvas) {
    if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) {
        return;
    }

    final RectF rect = mAlphaRect;

    if (BORDER_WIDTH_PX > 0) {
        mBorderPaint.setColor(mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX,
                rect.top - BORDER_WIDTH_PX,
                rect.right + BORDER_WIDTH_PX,
                rect.bottom + BORDER_WIDTH_PX,
                mBorderPaint);
    }

    mAlphaPattern.draw(canvas);

    float[] hsv = new float[] {
            mHue, mSat, mVal
    };
    int color = Color.HSVToColor(hsv);
    int acolor = Color.HSVToColor(0, hsv);

    mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
            color, acolor, TileMode.CLAMP);

    mAlphaPaint.setShader(mAlphaShader);

    canvas.drawRect(rect, mAlphaPaint);

    if (mAlphaSliderText != null && mAlphaSliderText != "") {
        canvas.drawText(mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity,
                mAlphaTextPaint);
    }

    float rectWidth = 4 * mDensity / 2;
    Point p = alphaToPoint(mAlpha);

    RectF r = new RectF();
    r.left = p.x - rectWidth;
    r.right = p.x + rectWidth;
    r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
    r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;

    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:47,代碼來源:ColorPickerView.java

示例11: setColor

public void setColor(int color) {
	int[] colors = new int[] {
			color,
			color,
			Color.argb(0, Color.red(color), Color.green(color),
					Color.blue(color)) };
	float[] points = new float[] { 0.0f, 1.0f, 1.0f };

	points[points.length - 2] = lastPOint;
	LinearGradient Lg = new LinearGradient(0, 2, 379, 2, colors, points,
			TileMode.CLAMP);
	Lg.setLocalMatrix(matrix);
	P0.setShader(Lg);
}
 
開發者ID:KishanV,項目名稱:Android-Canvas-Shape-Exporter-From-Flash-Symbol,代碼行數:14,代碼來源:textImg.java

示例12: draw

public void draw(@NonNull Canvas canvas) {
    if (this.mRebuildShader) {
        BitmapShader bitmapShader = new BitmapShader(this.mBitmap, this.mTileModeX, this
                .mTileModeY);
        if (this.mTileModeX == TileMode.CLAMP && this.mTileModeY == TileMode.CLAMP) {
            bitmapShader.setLocalMatrix(this.mShaderMatrix);
        }
        this.mBitmapPaint.setShader(bitmapShader);
        this.mRebuildShader = false;
    }
    if (this.mOval) {
        if (this.mBorderWidth > 0.0f) {
            canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
            canvas.drawOval(this.mBorderRect, this.mBorderPaint);
            return;
        }
        canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
    } else if (any(this.mCornersRounded)) {
        float radius = this.mCornerRadius;
        if (this.mBorderWidth > 0.0f) {
            canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
            canvas.drawRoundRect(this.mBorderRect, radius, radius, this.mBorderPaint);
            redrawBitmapForSquareCorners(canvas);
            redrawBorderForSquareCorners(canvas);
            return;
        }
        canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
        redrawBitmapForSquareCorners(canvas);
    } else {
        canvas.drawRect(this.mDrawableRect, this.mBitmapPaint);
        if (this.mBorderWidth > 0.0f) {
            canvas.drawRect(this.mBorderRect, this.mBorderPaint);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:35,代碼來源:RoundedDrawable.java

示例13: RoundedDrawable

public RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {
    this.cornerRadius = (float) cornerRadius;
    this.margin = margin;
    this.bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    this.mBitmapRect = new RectF((float) margin, (float) margin, (float) (bitmap.getWidth() - margin), (float) (bitmap.getHeight() - margin));
    this.paint = new Paint();
    this.paint.setAntiAlias(true);
    this.paint.setShader(this.bitmapShader);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:9,代碼來源:RoundedBitmapDisplayer.java

示例14: draw

public void draw(Canvas canvas) {
    if (this.mRebuildShader) {
        BitmapShader bitmapShader = new BitmapShader(this.mBitmap, this.mTileModeX, this.mTileModeY);
        if (this.mTileModeX == TileMode.CLAMP && this.mTileModeY == TileMode.CLAMP) {
            bitmapShader.setLocalMatrix(this.mShaderMatrix);
        }
        this.mBitmapPaint.setShader(bitmapShader);
        this.mRebuildShader = false;
    }
    if (this.mOval) {
        if (this.mBorderWidth > 0.0f) {
            canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
            canvas.drawOval(this.mBorderRect, this.mBorderPaint);
            return;
        }
        canvas.drawOval(this.mDrawableRect, this.mBitmapPaint);
    } else if (any(this.mCornersRounded)) {
        float radius = this.mCornerRadius;
        if (this.mBorderWidth > 0.0f) {
            canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
            canvas.drawRoundRect(this.mBorderRect, radius, radius, this.mBorderPaint);
            redrawBitmapForSquareCorners(canvas);
            redrawBorderForSquareCorners(canvas);
            return;
        }
        canvas.drawRoundRect(this.mDrawableRect, radius, radius, this.mBitmapPaint);
        redrawBitmapForSquareCorners(canvas);
    } else {
        canvas.drawRect(this.mDrawableRect, this.mBitmapPaint);
        if (this.mBorderWidth > 0.0f) {
            canvas.drawRect(this.mBorderRect, this.mBorderPaint);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:34,代碼來源:RoundedPagerDrawable.java

示例15: onBoundsChange

protected void onBoundsChange(Rect bounds) {
    super.onBoundsChange(bounds);
    RadialGradient vignette = new RadialGradient(this.mRect.centerX(), (this.mRect
            .centerY() * 1.0f) / 0.7f, this.mRect.centerX() * 1.3f, new int[]{0, 0,
            2130706432}, new float[]{0.0f, 0.7f, 1.0f}, TileMode.CLAMP);
    Matrix oval = new Matrix();
    oval.setScale(1.0f, 0.7f);
    vignette.setLocalMatrix(oval);
    this.paint.setShader(new ComposeShader(this.bitmapShader, vignette, Mode.SRC_OVER));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:10,代碼來源:RoundedVignetteBitmapDisplayer.java


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