扫描渐变:它是什么及其示例 [英] Sweep Gradient : What it is and its examples

查看:116
本文介绍了扫描渐变:它是什么及其示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 Android上的扫描渐变" ,我对此很感兴趣可以让我更好地控制颜色间隔和过渡.快速搜索后,发现几乎没有任何内容!

I came across Sweep Gradient on Android and was intrigued if it could give me a better control over the Color spacing and transitions. Did a quick search and found almost nothing about it!!

下面列出了我发现的仅有的几篇参考文献(它们符合接近甚至正确或全面地解释它的标准):

The only few references I found (and they do not meet the criteria of coming even close to explaining it properly or comprehensively) are listed below :

  • Sweep Gradient on Android (which only mentions commands to use - which is of almost no worth since right now I have no clue what Sweep Gradient is!)
  • android create pie dount with gradient and similar Questions (most of them relate to Rings - for which sweep is used)
  • Gradients in Photoshop (which talks about Angular Gradient which I think might be related to Sweep gradient)
  • Java Android Program to Demonstrate Sweep Gradient in Android (Again works with Rings)

差不多就可以了.其他人则相似或贬低.

So thats almost about it. Others are similar or disparagingly brief.

到目前为止,我几乎没有得出任何结论(也许是错误的):

Few conclusions I have drawn so far (and maybe are wrong) :

  • 扫描渐变主要用于
  • 它们用于类似于角度扫描的交易(不确定该交易),该交易谈论类似于钟针扫描的交易.
  • 非常类似于线性渐变.对于它们之间的区别,我唯一能想到的就是用法(例如Rings).
  • Center 进行交易(再次对时钟理论有很强的借鉴意义)
  • Sweep Gradient are mainly used for Rings
  • They are used for similar transactions as the Angular sweep (not sure about this one) which talks about transaction similar to sweep of a clock's hand.
  • Very similar to Linear Gradients. The only thing I can think about for a difference between them is for the usage (like Rings).
  • Sweep deals with Center (again a strong reference towards the clock theory)

我知道人们可能认为这并不是一个真正的技术问题.但是对于我使用Sweep Gradients或至少了解它们的含义而言,描述必须来自某个地方.而且,请提供有关振铃以外情况下使用Sweep的一些示例的答案.

I know people may consider this as not really a technical question. But for me to work with Sweep Gradients or atleast know what they mean, the description has to come from somewhere. And please do provide the answers with some examples of usage of Sweep in cases other than Rings.

推荐答案

在这种情况下,单词 gradient (在许多图形编辑器中,包括Photoshop)指的是在多个颜色,而不是仅使用一种颜色来填充区域.

The word gradient in this context (as in many graphics editors, including Photoshop) refers to a smooth transition between multiple colors, as opposed to using just a single color to fill an area.

Android API提供了3种不同的渐变:LinearGradientRadialGradientSweepGradient.

The Android API provides 3 different gradients: LinearGradient, RadialGradient and SweepGradient.

这些都是Shader的所有子类.您可以在Paint对象上设置Shader,然后使用该Paint绘制任何形状.形状将根据渐变的种类填充颜色并在它们之间进行过渡.

These are all subclasses of Shader. You can set a Shader on a Paint object, and then draw any shape with that Paint. The shape will be filled with colors and transitions between them, according to the kind of the gradient.

例如:

可以使用以下代码生成此图像:

This image can be produced with this code:

Bitmap test = Bitmap.createBitmap(640, 200, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(test);
{ // draw a dark gray background
    Paint backgroundPaint = new Paint();
    backgroundPaint.setARGB(255, 24, 24, 24);
    c.drawPaint(backgroundPaint);
}
Path heart = new Path();
{ // prepare a heart shape
    heart.moveTo(110, 175);
    heart.lineTo(10, 75);
    RectF leftCircle = new RectF(10, 25, 110, 125);
    heart.arcTo(leftCircle, 180, 180);
    RectF rightCircle = new RectF(110, 25, 210, 125);
    heart.arcTo(rightCircle, 180, 180);
    heart.close();
}
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(18f);
int[] colors = {
        0xFFFFFF88, // yellow
        0xFF0088FF, // blue
        0xFF000000, // black
        0xFFFFFF88  // yellow
};
float[] positions = {0.0f, 0.33f, 0.66f, 1.0f};
{ // draw the left heart
    SweepGradient sweepGradient;
    { // initialize the sweep gradient
        sweepGradient = new SweepGradient(50, 50, colors, positions);
        paint.setShader(sweepGradient);
    }
    c.drawPath(heart, paint);
    c.drawText("SweepGradient", 50, 190, paint);
}
{ // draw the middle heart
    LinearGradient linearGradient;
    { // initialize a linear gradient
        linearGradient = new LinearGradient(250, 0, 350, 150, colors, positions, Shader.TileMode.CLAMP);
        paint.setShader(linearGradient);
    }
    heart.offset(210, 0); // move the heart shape to the middle
    c.drawPath(heart, paint);
    c.drawText("LinearGradient", 260, 190, paint);
}
{ // draw the right heart
    RadialGradient radialGradient;
    { // initialize a linear gradient
        radialGradient = new RadialGradient(550, 50, 100, colors, positions, Shader.TileMode.CLAMP);
        paint.setShader(radialGradient);
    }
    heart.offset(210, 0); // move the heart shape to the right
    c.drawPath(heart, paint);
    c.drawText("RadialGradient", 470, 190, paint);
}
{ // save the bitmap
    String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "test.png";
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(filename);
        test.compress(Bitmap.CompressFormat.PNG, 90, out);
    } catch (Exception e) {
    } finally {
        try {
            out.close();
        } catch (Exception e) {
        }
    }
}

  • 因此,在您的Photoshop中,LinearGradientLinear GradientRadialGradientRadial Gradient,而SweepGradientAngular Gradient,如您的第三篇参考中所述.我建议先在图像编辑器中尝试使用它们(所有流行的图像编辑器都具有这些工具),您将很快了解它们的工作原理.

    • So the LinearGradient is Linear Gradient in Photoshop, RadialGradient is Radial Gradient, and SweepGradient is Angular Gradient, as described in your 3rd reference. I recommend trying these in an image editor first (all popular image editors have these tools), and you'll quickly get the idea of how they work.

      您也可以在 XML drawable 中使用这些渐变(就像您的第4个参考文献一样),但最多只能使用3种颜色.

      You can use these gradients in an XML drawable too (like in your 4th reference), with a limitation of using 3 colors maximum.

      SweepGradient中,提供位置时,0.0点位于3点钟处,沿顺时针方向移动(6点处0.25点,9点处0.5点,12点处0.75点)时间,然后在3点回到1.0).

      In a SweepGradient, when providing positions, the 0.0 point is at 3 o'clock, going clockwise (with 0.25 being at 6 o'clock, 0.5 at 9 o'clock, 0.75 at 12 o'clock, and 1.0 back at 3 o'clock).

      关于您的结论:

      • 如您所见,任何形状都可以用SweepGradient绘制,而不仅仅是圆环.在上面的示例中,甚至标签都是使用渐变绘制的.
      • 是的,时钟的指针比喻是正确的.
      • 在用法上,SweepGradientLinearGradient非常相似,不同之处在于您不需要提供TileMode,因为您不能在颜色列表的范围之外运行.
      • 是的,您需要提供中心点的坐标.
      • As you can see, any shape can be drawn with a SweepGradient, not just a ring. Even the labels are drawn with the gradients in the example above.
      • Yes, the clock's hand analogy is spot on.
      • In usage, SweepGradient is very similar to LinearGradient, except you don't need to provide a TileMode, because you cannot run outside of the bounds of your color list.
      • Yes, you need to provide the coordinates of the center point.

      我希望这可以解决它.

      这篇关于扫描渐变:它是什么及其示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆