The problem of drawing gradient effect

318 views
Skip to first unread message

becky

unread,
Sep 1, 2011, 9:51:17 AM9/1/11
to skia-discuss
I use skia to draw large rectangle with gradient effect, however, the
effect is not natural.
when the rectangle is small, the effect is good.

why?? do I use the API wrong?

Code is as follows.

SkPoint center;
center.set(160,240);
SkColor color[2];
color[0]=SkColorSetARGB(255,0,0,0);
color[1]=SkColorSetARGB(255,255,255,255);
SkShader *sh=SkGradientShader::CreateRadial(center,100,color,NULL,
2,SkShader::kClamp_TileMode,NULL);
SkPaint paint;
paint.setShader(sh);
SkRect r;
r.set(0, 0, 320, 480);
canv->drawRect(r, paint);

Elliot Poger

unread,
Sep 1, 2011, 10:25:01 AM9/1/11
to skia-d...@googlegroups.com, beib...@gmail.com
Becky, can you please attach images showing the large rectangle and the small one (showing one with "good" effect and another with "unnatural" effect)?


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To post to this group, send email to skia-d...@googlegroups.com.
To unsubscribe from this group, send email to skia-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/skia-discuss?hl=en.


旭赵

unread,
Sep 1, 2011, 11:10:55 AM9/1/11
to Elliot Poger, skia-d...@googlegroups.com
the big_gradient_skia_effect.png is the skia drawing effect on large rectangle, and the gradient color is with transparent 20%. and the big_gradient_origina_effect.png is the original effect. This effect is very poor compared to the original.

the small_gradient_skia_effect.png is the skia drawing effect on small rectangle, and the gradient color is with transparent 100%. the effect is ok.

by the way,I use skia to draw on android phone.
big_gradient_skia_effect.png
big_gradient_origina_effect.png
small_gradient_skia_effect.png

Elliot Poger

unread,
Sep 2, 2011, 5:46:50 PM9/2/11
to 旭赵, skia-d...@googlegroups.com
Becky, I'm a bit confused by the example you sent.  (I'm not sure which of those images was generated with the code snippet you sent, or where the "original" image came from.)

I have created a local modification to our "gradient" gm test that is based on your code snippet and generates rectangles of various sizes.

I am attaching here the code patch and the resulting image files I got when I ran it on Linux.  Here's how you can generate the images yourself using the patch...

cd .../trunk
patch -p0 <patch.txt
make -j gm
mkdir -p out/my-gm-images
out/Debug/gm -w out/my-gm-images
eog out/my-gm-images/gradient_sizes_*.png &


Can you please point out to me what about these images seems wrong to you?  Or modify the patch so that it DOES demonstrate the problem?
patch.txt
gradient_sizes_565.png
gradient_sizes_4444.png
gradient_sizes_8888.png
Reply all
Reply to author
Forward
0 new messages