欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

blackberry中, 创造用渐变色填充的圆角矩形背景

更新时间: 2014-01-05 02:42:31 责任编辑: Author_N1

 

blackberry中, 创建用渐变色填充的圆角矩形背景
创建用渐变色填充的圆角矩形背景
http://yy629.iteye.com 344850459 日期: 2010-07-22


这几天一直在学习blackberry开发, 记录一些有用的代码, 免得忘记了..

在blackberry中, 默认创建的渐变色背景都是矩形的, 有时我们需要绘制圆角矩形的渐变色背景, 所以就自己定义一个工厂类, 用来创建特殊的渐变色背景

代码如下

/**
 * @author YeYong
 * @date 2010-7-21 PM10:42:46
 */
public class SfBackgroundFactory {

  /**
   * 创建渐变色的圆角矩形背景
   * @param colorTopLeft - Starting color at top-left corner of background.
   * @param colorTopRight - Starting color at top-right corner of background.
   * @param colorBottomRight - Starting color at bottom-right corner of background.
   * @param colorBottomLeft - Starting color at bottom-left corner of background. 
   * @param arcWidth Width of arc used to round the four corners.
   * @param arcHeight Height of arc used to round the four corners.
   * @return
   */
  public static Background createLinearGradientRoundBackground(final int colorTopLeft,
      final int colorTopRight, final int colorBottomRight, final int colorBottomLeft, 
      final int arcWidth, final int arcHeight) {
    final Background bg = BackgroundFactory.createLinearGradientBackground(colorTopLeft, 
        colorTopRight, colorBottomRight, colorBottomLeft);
    return new Background() {
      public boolean isTransparent() {
        return bg.isTransparent();
      }

      public void draw(Graphics g, XYRect xyRect) {
        int width = xyRect.width;
        int height = xyRect.height;
        XYRect rect = new XYRect(0, 0, width, height);

        Bitmap bg1 = new Bitmap(width, height);
        Graphics g2 = Graphics.create(bg1);
        BackgroundFactory.createLinearGradientBackground(colorTopLeft, colorTopRight,
            colorBottomRight, colorBottomLeft).draw(g2, rect);

        Bitmap bg2 = new Bitmap(width, height);
        Graphics g3 = Graphics.create(bg2);
        g3.setColor(Color.BLACK);
        g3.fillRoundRect(0, 0, width, height, arcWidth, arcHeight);
        g3.rop(Graphics.ROP2_DSo, 0, 0, width, height, bg1, 0, 0);

        g.setColor(Color.WHITE);
        g.fillRoundRect(xyRect.x, xyRect.y, width, height, arcWidth, arcHeight);

        g.rop(Graphics.ROP2_DSa, xyRect.x, xyRect.y, width, height, bg2, 0, 0);
      }
    };
  }
}


效果图如下:

上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:42:31
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/13399/
本文WWW.DOC100.NET DOC100.NET版权所有。