`

SWT圆角窗口绘制

    博客分类:
  • SWT
阅读更多

SWT窗口如果要使用自己的不规则图片做背景,就需要手动编码去处理png图片中那些透明的部分。可以说是一像素一像素去处理,比较繁琐,所以不推荐透明区域太大的图片(影响重绘的进度),基本做一个圆角什么就可以了。

 

这里提供一个函数来处理一个图片区域的透明部分:

 

private Region handleTransparenceRegion(Image image, int offsetX, int offsetY) {    
    Region region = new Region();    
    final ImageData imageData = image.getImageData();    
    if (imageData.alphaData != null) {    
        Rectangle pixel = new Rectangle(0, 0, 1, 1);    
        for (int y = 0; y < imageData.height; y++) {    
            for (int x = 0; x < imageData.width; x++) {    
                if (imageData.getAlpha(x, y) != 255) {    
                    pixel.x = imageData.x + x + offsetX;     
                    pixel.y = imageData.y + y + offsetY;               
                    region.add(pixel);    
                }    
             }    
         }    
     }    
   return region;    
}   

 

首先获得整个界面的边界:

view plaincopy to clipboardprint?
Region allRegion = new Region();    
allRegion.add(0, 0, getSize().x, getSize().y); 

   

 

然后把透明处理之后的部分重新subtract一下:

allRegion.subtract(handleTransparenceRegion(img,0,0));  

 

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Ant_Yan/archive/2009/03/28/4031723.aspx

分享到:
评论
1 楼 javenwong 2017-07-14  
你好,我现在需要给一个Composite做圆角处理,不知道怎么得到一个圆角矩形的posArray,可否帮忙,QQ 42832899 谢谢!!

相关推荐

Global site tag (gtag.js) - Google Analytics