你好,游客 登录 注册 搜索
背景:
阅读新闻

Android自定义带倒影和偏转的超炫Gallery

[日期:2012-06-18] 来源:Linux社区  作者:aomandeshangxiao [字体:大 中 小]

先获取倒影,然后把倒影和原照片合成一张图片。里面使用到了bitmap的静态方法createBitmap(),看下官方文档:

  1. public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)  
  2.   
  3. Since: API Level 1  
  4. Returns an immutable bitmap from subset of the source bitmap, transformed by the optional matrix. It is initialized with the same density as the original bitmap.  
  5. Parameters  
  6.   
  7. source  The bitmap we are subsetting  
  8. x   The x coordinate of the first pixel in source  
  9. y   The y coordinate of the first pixel in source  
  10. width   The number of pixels in each row  
  11. height  The number of rows  
  12. m   Optional matrix to be applied to the pixels  
  13. filter  true if the source should be filtered. Only applies if the matrix contains more than just translation.  
  14. Returns  
  15.   
  16. A bitmap that represents the specified subset of source  
  17. Throws  
  18.   
  19. IllegalArgumentException    if the x, y, width, height values are outside of the dimensions of the source bitmap.

参数x、y就是开始复制的起点坐标,就是从原图的那个坐标点开始复制,width设置复制的宽度,height设置高度。

因为代码中注释较详细,这里不再多说。

下面这段代码是设置渐变效果:

  1. /** 
  2.        * 参数一:为渐变起初点坐标x位置, 
  3.        * 参数二:为y轴位置, 
  4.        * 参数三和四:分辨对应渐变终点, 
  5.        * 最后参数为平铺方式, 
  6.        * 这里设置为镜像Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变 
  7.        */  
  8.       LinearGradient shader = new LinearGradient(0,originalImage.getHeight(), 0,  
  9.               bitmapWithReflection.getHeight() + reflectionGap,0x70ffffff, 0x00ffffff, TileMode.MIRROR);  

看完倒影,再来看一下偏转,在main.xml文件中:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical"  
  6.     >  
  7.     <nsouth.jonas.android.GalleryFlow   
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent"  
  10.         android:gravity="center_vertical"  
  11.         android:id="@+id/gallery"  
  12.     />  
  13. </LinearLayout>  
linux
相关资讯       Android源码 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2013/10/9 10:23:10
能不能把你的xml布局代码也发出来啊!