I would like to try and start a new series of articles focused on giving you small recipes you can use in your applications to achieve very specific visual effects. For this first installment, I will show you how to draw a bitmap with rounded corners. Many people have asked me how to achieve this effect and I often see developers use a much more complicated solution than is necessary.
I wrote a simple application to illustrate this effect. You can download an APK for your Android device and download the source code. This is what the application looks like:
To generate the rounded images I simply wrote a custom Drawable that draws a rounded rectangle using Canvas.drawRoundRect(). The trick is to use a Paint with a BitmapShader to fill the rounded rectangle with a texture instead of a simple color. Here is what the code looks like:
BitmapShader shader; shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); RectF rect = new RectF(0.0f, 0.0f, width, height); // rect contains the bounds of the shape // radius is the radius in pixels of the rounded corners // paint contains the shader that will texture the shape canvas.drawRoundRect(rect, radius, radius, paint);
The sample application goes a little further and fakes a vignette effect by combining the BitmapShader with a RadialGradient.
Download free full apk Splashtop Remote Desktop HD v1.9.10.2 for Android
i always admire PETA, they really protect some of the helpless animals on this planet,.
Thank you for making the sincere attempt to explain this. I feel very sturdy about this and also find out more. If its OK, as you reach more in depth knowledge, would you mind including more posts similar to this one with more information? It might be extremely helpful and great for me and my colleagues.