我正在创建自己的带有渐变背景的UITableViewCells.我已经完成了所有的逻辑和绘图,但我想解决的一件事是我的自定义单元格角落周围的"厚片":
如果你放大角落,你可以看到我在说什么.这是我用来生成单元格的代码:
CGContextRef c = UIGraphicsGetCurrentContext();
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = nil;
CGFloat components[8] = TABLE_CELL_BACKGROUND;
CGContextSetStrokeColorWithColor(c, [[UAColor colorWithWhite:0.7 alpha:1] CGColor]);
CGContextSetLineWidth(c, 2);
CGContextSetAllowsAntialiasing(c, YES);
CGContextSetShouldAntialias(c, YES);
CGFloat minx = CGRectGetMinX(rect) , midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ;
CGFloat miny = CGRectGetMinY(rect) , maxy = CGRectGetMaxY(rect) ;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, minx, miny);
CGPathAddArcToPoint(path, NULL, minx, maxy, midx, maxy, kDefaultMargin);
CGPathAddArcToPoint(path, NULL, maxx, maxy, maxx, miny, kDefaultMargin);
CGPathAddLineToPoint(path, NULL, maxx, miny);
CGPathAddLineToPoint(path, NULL, minx, …Run Code Online (Sandbox Code Playgroud) 我有一个自定义按钮,并通过编程方式更改其按下和默认颜色.
public class CustomApplicationButton extends Button {
public CustomApplicationButton(Context context) {
this(context, 0, 0, 0);
}
public CustomApplicationButton(Context context, int topDrawableResId, int outlineDefaultColorId, int outlinePressedColorId) {
super(context);
// set width and height
LinearLayout.LayoutParams params = new LayoutParams(
context.getResources().getDimensionPixelSize(R.dimen.sr_application_button_width),
context.getResources().getDimensionPixelSize(R.dimen.sr_application_button_height));
setLayoutParams(params);
// set drawable top icon
if (topDrawableResId != 0) {
setCompoundDrawablesWithIntrinsicBounds(0, topDrawableResId, 0, 0);
}
// set background and outline color
int strokeWidth = context.getResources().getDimensionPixelSize(R.dimen.sr_launcher_button_stroke_size);
// unpressed state drawable
LayerDrawable defaultLayers = (LayerDrawable) context.getResources().getDrawable(
R.drawable.btn_launcher_shape_default);
GradientDrawable defaultShapeOutline = (GradientDrawable) defaultLayers.findDrawableByLayerId(R.id.outline_default); …Run Code Online (Sandbox Code Playgroud) 嗨,我已经实现了进度条,它工作正常,但我的问题是我需要使用油漆给一个唯一的边框圆.我研究过这个,但是它占据了所有的圆形区域,我只需要边框.
我的油漆代码:
mCirclePaint = new Paint();
mCirclePaint.setAntiAlias(true);
mCirclePaint.setDither(true);
mCirclePaint.setColor(mCircleColor);
mCirclePaint.setStrokeWidth(mCircleStrokeWidth);
mCirclePaint.setStyle(Paint.Style.STROKE);
mCirclePaint.setStrokeJoin(Paint.Join.MITER);
// mCirclePaint.setShadowLayer(4.0f, 0.0f, 2.0f, Color.BLACK);
mCirclePaint.setStrokeCap(Paint.Cap.SQUARE);
canvas.drawPath(mCirclePath, mCirclePaint)
Run Code Online (Sandbox Code Playgroud) 当我在画布中绘制文本时,我会得到丑陋的尖峰,如下所示:

在这里试试:http://jsfiddle.net/48m4B/
例如在photoshop中,我得到了这个:

代码只是一个经典的strokeText:
ctx.font = '20px Arial';
ctx.lineWidth = 15;
ctx.strokeStyle = '#fff';
ctx.strokeText('How to prevent ugly spikes?');
Run Code Online (Sandbox Code Playgroud)
如果无法解决此问题,是否有解决方法?
我有以下代码:
private _x,_y,_w,_h;
protected void paintComponent( Graphics g_ ) {
g_.setStroke( new BasicStroke(2) );
g_.drawLine(_x, _y, _x+_w, _y+_h);
g_.drawLine(_x, _y+_h, _x+_w, _y);
}
Run Code Online (Sandbox Code Playgroud)
就我而言,我正在绘制正方形的对角线,因此:_w==_h。
我的问题是这两行的外观并不相同:第一行看起来比第二行更粗。检查绘制的实际像素时,这里是渲染的区别:

我并不在乎哪一个应该被认为是“正确的”(尽管我想了解这一结果的原因),但是我想在这里保持一定的连贯性,即这两行具有相同的渲染:我该怎么做那?
(当我使用1px笔触时,两行之间没有区别)。
Olavi的答案的后续行动:
对于笔划使用奇数个像素不能解决问题:

启用抗锯齿会导致另一个问题:绘制十字的正方形的笔触变得模糊:

我这里有一个 ShapeableImageView,笔画为 5dp:
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/profile_picture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/profile_toolbar"
app:shapeAppearanceOverlay="@style/circular"
app:strokeColor="@color/dark_blue"
app:strokeWidth="5dp" />
Run Code Online (Sandbox Code Playgroud)
这是结果:
我的最终目标是做出这样的效果: http: //codepen.io/yoksel/pen/XJbzrO(页面底部)。但我什至无法让这个简单的文本大纲发挥作用。
<!DOCTYPE html>
<html lang = "en-US">
<head>
<title> Test </title>
<style>
#title {
color: blue;
stroke: red;
stroke-width: 2px;
}
</style>
</head>
<body>
<h1 id="title">This is some text</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
该解决方案必须适用于所有主要浏览器。我正在使用谷歌浏览器。如果无法通过这种方式完成描边,请不要建议使用阴影。我无法将阴影变成所需的效果。
我有以下Codepen,我试图在其中为图像周围的圆圈设置动画。
到目前为止,我有一个圆形 SVG 正在剪辑图像,但它没有显示 clipPath 内部的笔划。
如何让边框显示?
class App extends React.Component {
render() {
return (
<svg width='48' height='48'>
<defs>
<clipPath id='circleView'>
<circle cx='24' cy='24' r='23' fill='none' stroke='red' strokeWidth='2' />
</clipPath>
</defs>
<image width='48' height='48' xlinkHref={'https://source.unsplash.com/random'} clipPath='url(#circleView)' />
</svg>
)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 d3 构建仪表板,并将布局构建为响应式网格。我正在使用 d3 为网格中的每个项目添加一个 svg 元素,当我添加 svg 元素时,我还添加了一个相对于每个网格项目的大小进行定位和缩放的矩形。rect 的笔触 (stroke-width=1) 总是被画得很模糊,唯一让它清晰的方法是在 rect 的 x 和 y 位置加上 0.5。
我了解抗锯齿是什么以及这从根本上是什么导致了模糊的线条。我试图了解如何/在哪里/为什么将 rects 放置 0.5 off,或者默认情况下它们是否放置在像素之间。
我使用 .clientHeight/.clientWidth 来设置 svg 元素的视图框,并设置矩形的大小。这两个变量都返回整数。我使用“fr”单位来定义网格,我尝试切换到绝对像素值,但没有帮助。
非常感谢,这里有一个片段和一个 codepen 项目:
let rect = svg.selectAll('rect').data([null]);
rect.enter().append('rect')
.merge(rect)
.attr('x', 10) // if I make these values '10.5'
.attr('y', 10) // then everything looks crisp...
.attr('width', props.width - 20)
.attr('height', props.height - 20)
.style('fill', 'none')
.style('stroke', '#FFFFFF')
.style('stroke-width', '1')
Run Code Online (Sandbox Code Playgroud)