本文整理汇总了Java中android.graphics.Shader.TileMode.MIRROR属性的典型用法代码示例。如果您正苦于以下问题:Java TileMode.MIRROR属性的具体用法?Java TileMode.MIRROR怎么用?Java TileMode.MIRROR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.graphics.Shader.TileMode
的用法示例。
在下文中一共展示了TileMode.MIRROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createReflectedImage
/**
* 全倒影
*
* @param originalImage
* @return
*/
public static Bitmap createReflectedImage(Bitmap originalImage, int imageHeight) {
int width = originalImage.getWidth();
int height = originalImage.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height - imageHeight, width, imageHeight, matrix, false);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + imageHeight), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
Paint defaultpPaint = new Paint();
canvas.drawBitmap(originalImage, 0, 0, defaultpPaint);
canvas.drawBitmap(reflectionImage, 0, height, defaultpPaint);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight(), paint);
reflectionImage.recycle();
return bitmapWithReflection;
}
示例2: LinearGradientView
public LinearGradientView(Context context) {
super(context);
// ��һ�ڶ���������ʾ������㣬���������ڶԽǵ�����λ�ã��������ĸ�������ʾ�����յ㣻�����������ʾ������ɫ��
// ��������������Ϊ�գ���ʾ����ֵΪ0-1 new float[] {0.25f, 0.5f, 0.75f, 1 } ���Ϊ�գ���ɫ���ȷֲ������ݶ��ߡ�
mLinearGradient11 = new LinearGradient(0, 0, 0, 200, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, null, TileMode.CLAMP);
mLinearGradient12 = new LinearGradient(0, 0, 0, 300, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, new float[] { 0, 0.1f, 0.5f, 0.5f }, TileMode.CLAMP);
mLinearGradient13 = new LinearGradient(0, 0, 0, 400, new int[] { Color.RED, Color.GREEN, Color.BLUE }, null, TileMode.CLAMP);
mLinearGradient21 = new LinearGradient(0, 320, 0, 320 + 200, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, null, TileMode.MIRROR);
mLinearGradient22 = new LinearGradient(0, 320, 0, 320 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, null, TileMode.MIRROR);
mLinearGradient23 = new LinearGradient(0, 320, 0, 320 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, new float[] { 0, 0.1f, 0.5f }, TileMode.MIRROR);
mLinearGradient31 = new LinearGradient(0, 640, 0, 640 + 200, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, null, TileMode.REPEAT);
mLinearGradient32 = new LinearGradient(0, 640, 0, 640 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, null, TileMode.REPEAT);
mLinearGradient33 = new LinearGradient(0, 640, 0, 640 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, new float[] { 0, 0.1f, 0.5f }, TileMode.REPEAT);
mPaint = new Paint();
}
示例3: onLayout
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
super.onLayout(changed, left, top, right, bottom);
int width = getWidth();
int height = getHeight();
mRectF.left = 0;
mRectF.top = 0;
mRectF.right = width;
mRectF.bottom = height;
if (mShaderV == null)
{
mShaderV = new LinearGradient(0, mRectF.top, 0, mRectF.bottom, mColorsV, null, TileMode.MIRROR);
mPaintV.setShader(mShaderV);
}
if (mShaderH == null)
{
mShaderH = new LinearGradient(mRectF.left, 0, mRectF.right, 0, mColorsH, mPositionsH, TileMode.MIRROR);
mPaintH.setShader(mShaderH);
}
}
示例4: drawMask
/**
* 绘制遮盖板
*
* @param canvas
*/
private void drawMask(Canvas canvas) {
LinearGradient lg = new LinearGradient(0, 0, 0, maskHight, 0x00f2f2f2,
0x00f2f2f2, TileMode.MIRROR);
Paint paint = new Paint();
paint.setShader(lg);
canvas.drawRect(0, 0, controlWidth, maskHight, paint);
LinearGradient lg2 = new LinearGradient(0, controlHeight - maskHight,
0, controlHeight, 0x00f2f2f2, 0x00f2f2f2, TileMode.MIRROR);
Paint paint2 = new Paint();
paint2.setShader(lg2);
canvas.drawRect(0, controlHeight - maskHight, controlWidth,
controlHeight, paint2);
}
示例5: drawMask
/**
* 绘制遮盖板
*
* @param canvas
*/
private void drawMask(Canvas canvas) {
LinearGradient lg = new LinearGradient(0, 0, 0, maskHight, 0x00f2f2f2,
0x00f2f2f2, TileMode.MIRROR);
Paint paint = new Paint();
paint.setShader(lg);
canvas.drawRect(0, 0, controlWidth, maskHight, paint);
LinearGradient lg2 = new LinearGradient(0, controlHeight - maskHight,
0, controlHeight, 0x00f2f2f2, 0x00f2f2f2, TileMode.MIRROR);
Paint paint2 = new Paint();
paint2.setShader(lg2);
canvas.drawRect(0, controlHeight - maskHight, controlWidth,
controlHeight, paint2);
}
示例6: parseTileMode
private static TileMode parseTileMode(int tileMode) {
switch (tileMode) {
case 0:
return TileMode.CLAMP;
case 1:
return TileMode.REPEAT;
case 2:
return TileMode.MIRROR;
default:
return null;
}
}
示例7: createReflectedImage
/**
* 图片创建倒影 TODO(这里用一句话描述这个方法的作用)
*
* @author 2013-10-12 下午3:58:39
* @param originalImage
* @param number
* @return Bitmap
*/
public static Bitmap createReflectedImage(Bitmap originalImage, int number)
{
final int reflectionGap = 0; // 倒影和原图片间的距离
int width = originalImage.getWidth();
int height = originalImage.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
double reflectHeight = number / 100.00;
number = (int)(height * reflectHeight);
// 倒影部分
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, number, width, number, matrix, false);
// 要返回的倒影图片
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + number), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
// 画原来的图片
canvas.drawBitmap(originalImage, 0, 0, null);
// Paint defaultPaint = new Paint();
// //倒影和原图片间的距离
// canvas.drawRect(0, height, width, height + reflectionGap,
// defaultPaint);
// 画倒影部分
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader =
new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap,
0x70ffffff, 0x00ffffff, TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
示例8: createReflectedImage
/**
* 倒影图片
* @param originalBitmap
* @return
*/
public static Bitmap createReflectedImage(Bitmap originalBitmap) {
final int reflectionGap = 4;
int width = originalBitmap.getWidth();
int height = originalBitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionBitmap = Bitmap.createBitmap(originalBitmap, 0,
height / 2, width, height / 2, matrix, false);
Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height
+ height / 2 + reflectionGap), Config.ARGB_8888);
Canvas canvas = new Canvas(withReflectionBitmap);
canvas.drawBitmap(originalBitmap, 0, 0, null);
Paint defaultPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0,
originalBitmap.getHeight(), 0,
withReflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff,
TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(),
paint);
return withReflectionBitmap;
}
示例9: onSizeChanged
@Override
protected void onSizeChanged(int new_x, int new_y, int old_x, int old_y)
{
super.onSizeChanged(new_x, new_y, old_x, old_y);
float center_x = getMeasuredWidth() / 2.0F;
float center_y = getMeasuredHeight()/ 2.0F;
float radius = Math.min(center_x, center_y);
shader_y = new RadialGradient(center_x, center_y, radius, Color.TRANSPARENT, Color.BLACK, TileMode.MIRROR);
}
示例10: createReflectedImage
/**
* 网上找的方法,实现图片倒影效果
*
* @param originalImage
* @return
*/
public Bitmap createReflectedImage(Bitmap originalImage)
{
int width = originalImage.getWidth();
int height = originalImage.getHeight();
Matrix matrix = new Matrix();
// 实现图片翻转90度
matrix.preScale(1, -1);
// 创建倒影图片(是原始图片的一半大小)
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height / 2, width, height / 2, matrix, false);
// 创建总图片(原图片 + 倒影图片)
Bitmap finalReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);
// 创建画布
Canvas canvas = new Canvas(finalReflection);
canvas.drawBitmap(originalImage, 0, 0, null);
//把倒影图片画到画布上
canvas.drawBitmap(reflectionImage, 0, height + 5, null);
Paint shaderPaint = new Paint();
//创建线性渐变LinearGradient对象
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, finalReflection.getHeight() + 5, 0x70ffffff,
0x00ffffff, TileMode.MIRROR);
shaderPaint.setShader(shader);
shaderPaint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
//画布画出反转图片大小区域,然后把渐变效果加到其中,就出现了图片的倒影效果。
canvas.drawRect(0, height + 1, width, finalReflection.getHeight() + 5, shaderPaint);
return finalReflection;
}
示例11: createReflectedImage
public static Bitmap createReflectedImage(Bitmap originalImage) {
final int reflectionGap = 4; //倒影和原图片间的距离
int width = originalImage.getWidth();
int height = originalImage.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
//倒影部分
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 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(originalImage, 0, 0, null);
Paint defaultPaint = new Paint();
//倒影和原图片间的距离
canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
//画倒影部分
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
return bitmapWithReflection;
}
示例12: drawAxisHandler
public void drawAxisHandler(Canvas canvas)
{
if (minValue == maxValue)
{
minValue = minValue * 0.5;
maxValue = maxValue * 1.5;
}
if (minorTicks == MathHelper.NULL_VALUE)
{
minorTicks = (maxValue - minValue) / (interval * multipleSpacer);
}
if (majorTicks == MathHelper.NULL_VALUE)
{
majorTicks = (maxValue - minValue) / interval;
}
paint.setAntiAlias(true);
float shortRadius = radius * .9f;
float longRadius = radius * 1.05f;
paint.setColor(0xffA2D87F);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(10);
canvas.drawArc(oval, maxAngle, 360, true, paint);
paint.setStyle(Style.FILL);
Shader gradient =
new RadialGradient(centerX, centerY, shortRadius, gradientColors[0], gradientColors[1],
TileMode.MIRROR);
paint.setShader(gradient);
oval.left = oval.left + 6;
oval.top = oval.top + 6;
oval.right = oval.right - 6;
oval.bottom = oval.bottom - 6;
canvas.drawArc(oval, maxAngle, 360, true, paint);
paint.setShader(null);
paint.setColor(Color.RED);
paint.setStyle(Style.FILL);
paint.setStrokeWidth(2);
drawTicks(canvas, longRadius, radius, minorTicks, false);
drawTicks(canvas, longRadius, shortRadius, majorTicks, true);
}
示例13: SlideView
public SlideView(Context context, AttributeSet attrs) {
super(context, attrs);
ViewConfiguration configuration = ViewConfiguration.get(context);
mMaxVelocity = configuration.getScaledMaximumFlingVelocity();
mInterpolator = new AccelerateDecelerateInterpolator();
mDensity = getResources().getDisplayMetrics().density;
setClickable(true);
setFocusable(true);
setFocusableInTouchMode(true);
TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.SlideView);
mText = typeArray.getString(R.styleable.SlideView_maskText);
mTextSize = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextSize, R.dimen.mask_text_size);
mTextLeft = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextMarginLeft, R.dimen.mask_text_margin_left);
mTextTop = typeArray.getDimensionPixelSize(R.styleable.SlideView_maskTextMarginTop, R.dimen.mask_text_margin_top);
mSlider = typeArray.getResourceId(R.styleable.SlideView_slider, R.mipmap.app_icon);
mSliderLeft = typeArray.getDimensionPixelSize(R.styleable.SlideView_sliderMarginLeft, R.dimen.slider_margin_left);
mSliderTop = typeArray.getDimensionPixelSize(R.styleable.SlideView_sliderMarginTop, R.dimen.slider_margin_top);
mSliderBitmap = BitmapFactory.decodeResource(getResources(), mSlider);
mSliderRect = new Rect(mSliderLeft, mSliderTop, mSliderLeft + mSliderBitmap.getWidth(), mSliderTop + mSliderBitmap.getHeight());
mSlidableLength = typeArray.getDimensionPixelSize(R.styleable.SlideView_slidableLength, R.dimen.slidable_length);
mEffectiveLength = typeArray.getDimensionPixelSize(R.styleable.SlideView_effectiveLength,
R.dimen.effective_length);
mEffectiveVelocity = typeArray.getDimensionPixelSize(R.styleable.SlideView_effectiveVelocity,
R.dimen.effective_velocity);
typeArray.recycle();
mGradientColors = new int[]{Color.argb(255, 120, 120, 120), Color.argb(255, 120, 120, 120), Color.argb(255, 255, 255, 255)};
mGradient = new LinearGradient(0, 0, 100 * mDensity, 0, mGradientColors, new float[]{0, 0.7f, 1}, TileMode.MIRROR);
mGradientIndex = 0;
mPaint = new Paint();
mMatrix = new Matrix();
mPaint.setTextSize(mTextSize);
mHandler.sendEmptyMessageDelayed(MSG_REDRAW, DRAW_INTERVAL);
}
示例14: createReflectedImageWithOriginalBitmap
/**
* 同时创建 图片及其自身倒影
*
* @param originalBitmap
* 需要倒过来的 图片
* @param reflectionGap
* 图片与倒影间隔距离
* @return 图片及其自身倒影
*/
public static Bitmap createReflectedImageWithOriginalBitmap(Bitmap originalBitmap, final int reflectionGap) {
// 图片的宽度
int width = originalBitmap.getWidth();
// 图片的高度
int height = originalBitmap.getHeight();
if (height <= reflectionGap) {
return null;
}
Matrix matrix = new Matrix();
// 图片缩放,x轴变为原来的1倍,y轴为-1倍,实现图片的反转
matrix.preScale(1, -1);
// 创建反转后的图片Bitmap对象,图片高是原图的一半。
Bitmap reflectionBitmap = Bitmap.createBitmap(originalBitmap, 0, height / 2, width, height / 2, matrix, false);
// 创建标准的Bitmap对象,宽和原图一致,高是原图的1.5倍。
Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height + height / 2 + reflectionGap), Config.ARGB_8888);
// 构造函数传入Bitmap对象,为了在图片上画图
Canvas canvas = new Canvas(withReflectionBitmap);
// 画原始图片
canvas.drawBitmap(originalBitmap, 0, 0, null);
// 画间隔矩形
Paint defaultPaint = new Paint();
int itsColor = android.R.color.transparent;
defaultPaint.setColor(itsColor);
canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
// 画倒影图片
canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null);
// 实现倒影效果
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, originalBitmap.getHeight(), 0, withReflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.MIRROR);
// LinearGradient shader = new LinearGradient(0, originalBitmap.getHeight(), 0, withReflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// 覆盖效果
canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(), paint);
return withReflectionBitmap;
}
示例15: doGradient
private Gradient doGradient(boolean isLinear, Attributes atts)
{
Gradient gradient = new Gradient();
gradient.id = getStringAttr("id", atts);
gradient.isLinear = isLinear;
if (isLinear)
{
gradient.x1 = getFloatAttr("x1", atts, 0f);
gradient.x2 = getFloatAttr("x2", atts, 1f);
gradient.y1 = getFloatAttr("y1", atts, 0f);
gradient.y2 = getFloatAttr("y2", atts, 0f);
}
else
{
gradient.x = getFloatAttr("cx", atts, 0f);
gradient.y = getFloatAttr("cy", atts, 0f);
gradient.radius = getFloatAttr("r", atts, 0f);
}
String transform = getStringAttr("gradientTransform", atts);
if (transform != null)
{
gradient.matrix = parseTransform(transform);
}
String spreadMethod = getStringAttr("spreadMethod", atts);
if (spreadMethod == null)
{
spreadMethod = "pad";
}
gradient.tilemode = (spreadMethod.equals("reflect")) ? TileMode.MIRROR : (spreadMethod.equals("repeat")) ? TileMode.REPEAT : TileMode.CLAMP;
String unit = getStringAttr("gradientUnits", atts);
if (unit == null)
{
unit = "objectBoundingBox";
}
gradient.boundingBox = !unit.equals("userSpaceOnUse");
String xlink = getStringAttr("href", atts);
if (xlink != null)
{
if (xlink.startsWith("#"))
{
xlink = xlink.substring(1);
}
gradient.xlink = xlink;
}
return gradient;
}