中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android中實現(xiàn)圖片倒影的代碼

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
/*實現(xiàn)圖片倒影(tested)*/
public class ButtonImageActivity extends Activity {
    /** Called when the activity is first created. */
    private ImageView image_btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image_btn=(ImageView)findViewById(R.id.image_btn);
        Bitmap bitmap =((BitmapDrawable)getResources().getDrawable(R.drawable.image_btn)).getBitmap();
        image_btn.setImageBitmap(createReflectedImage(bitmap));
        image_btn.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
    }
    private Bitmap createReflectedImage(Bitmap originalBitmap) {  
        // 圖片與倒影間隔距離  
        final int reflectionGap = 4;  

        // 圖片的寬度  
        int width = originalBitmap.getWidth();  
        // 圖片的高度  
        int height = originalBitmap.getHeight();  

        Matrix matrix = new Matrix();  
        // 圖片縮放,x軸變?yōu)樵瓉淼?倍,y軸為-1倍,實現(xiàn)圖片的反轉(zhuǎn)  
        matrix.preScale(1, -1);  
        // 創(chuàng)建反轉(zhuǎn)后的圖片Bitmap對象,圖片高是原圖的一半。  
        Bitmap reflectionBitmap = Bitmap.createBitmap(originalBitmap, 0,  
                height / 2, width, height / 2, matrix, false);  
        // 創(chuàng)建標(biāo)準(zhǔn)的Bitmap對象,寬和原圖一致,高是原圖的1.5倍。  
        Bitmap withReflectionBitmap = Bitmap.createBitmap(width, (height  
                + height / 2 + reflectionGap), Config.ARGB_8888);  

        // 構(gòu)造函數(shù)傳入Bitmap對象,為了在圖片上畫圖  
        Canvas canvas = new Canvas(withReflectionBitmap);  
        // 畫原始圖片  
        canvas.drawBitmap(originalBitmap, 0, 0, null);  

        // 畫間隔矩形  
        Paint defaultPaint = new Paint();  
        canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);  

        // 畫倒影圖片  
        canvas.drawBitmap(reflectionBitmap, 0, height + reflectionGap, null);  

        // 實現(xiàn)倒影效果  
        Paint paint = new Paint();  
        LinearGradient shader = new LinearGradient(0, originalBitmap.getHeight(),   
                0, withReflectionBitmap.getHeight(), 0x70ffffff, 0x00ffffff,  
                TileMode.MIRROR);  
        paint.setShader(shader);  
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));  

        // 覆蓋效果  
        canvas.drawRect(0, height, width, withReflectionBitmap.getHeight(), paint);  

        return withReflectionBitmap;  
    }  
} 

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:生成一定數(shù)量的不重復(fù)隨機數(shù)的PHP代碼

下一篇:演示如何使用Java BufferedOutputStream類寫文件