Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1107389
  • 博文数量: 276
  • 博客积分: 8317
  • 博客等级: 少将
  • 技术积分: 2329
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-12 08:17
个人简介

http://ads.buzzcity.net/adpage.php?partnerid=40096

文章分类

全部博文(276)

文章存档

2013年(1)

2012年(38)

2011年(102)

2010年(85)

2009年(45)

2008年(5)

分类: LINUX

2010-04-17 22:37:51

public static Bitmap createReflectedImage(Context context, Bitmap originalImage) {  
                   //The gap we want between the reflection and the original image  
                   final int reflectionGap = 4;  
                     
                        int width = originalImage.getWidth(); 
                        int height = originalImage.getHeight(); 
                          
                    
                        //This will not scale but will flip on the Y axis 
                        Matrix matrix = new Matrix(); 
                        matrix.preScale(1, -1); 
                          
                        //Create a Bitmap with the flip matrix applied to it. 
                        //We only want the bottom half of the image 
                        Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height/2, width, height/2, matrix, false); 
                          
                              
                        //Create a new bitmap with same width but taller to fit reflection 
                        Bitmap bitmapWithReflection = Bitmap.createBitmap(width 
                          , (height + height/2), Config.ARGB_8888); 
                        
                       //Create a new Canvas with the bitmap that's big enough for 
                       //the image plus gap plus reflection 
                       Canvas canvas = new Canvas(bitmapWithReflection); 
                       //Draw in the original image 
                       canvas.drawBitmap(originalImage, 0, 0, null); 
                       //Draw in the gap 
                       Paint defaultPaint = new Paint(); 
                       canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); 
                       //Draw in the reflection 
                       canvas.drawBitmap(reflectionImage,0, height + reflectionGap, null); 
                         
                       //Create a shader that is a linear gradient that covers the reflection 
                       Paint paint = new Paint(); 
                       LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, 
                         bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, 
                         TileMode.CLAMP); 
                      //Set the paint to use this shader (linear gradient) 
                       paint.setShader(shader); 
                       //Set the Transfer mode to be porter duff and destination in 
                       paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); 
                       //Draw a rectangle using the paint with our linear gradient 
                       canvas.drawRect(0, height, width, 
                       bitmapWithReflection.getHeight() + reflectionGap, paint); 
                        
                   return bitmapWithReflection; 
           }
阅读(1100) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-12 18:33:53

很好,非常感谢