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);
      }
    };
  }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值