First, Post:
1. layout file Main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" fill_parent " android:layout_height=" fill_parent " android:o rientation= "vertical" > <textview android:layout_width= "fill_parent" android:layout_height= " Wrap_content " android:text=" @string/hello "/> <imageview android:id=" @+id/picture_qian " Android:layout_width= "Fill_parent" android:layout_height= "fill_parent" android:src= "@drawable/horse" /></linearlayout>
2.MainActivity Interface Java code:
1 Packagecom.easymorse.picture;2 3 Importandroid.app.Activity;4 ImportAndroid.graphics.Bitmap;5 ImportAndroid.graphics.Bitmap.Config;6 ImportAndroid.graphics.Canvas;7 Importandroid.graphics.LinearGradient;8 ImportAndroid.graphics.Matrix;9 ImportAndroid.graphics.Paint;Ten ImportAndroid.graphics.PorterDuff.Mode; One ImportAndroid.graphics.PorterDuffXfermode; A ImportAndroid.graphics.Shader.TileMode; - Importandroid.graphics.drawable.BitmapDrawable; - ImportAndroid.os.Bundle; the ImportAndroid.widget.ImageView; - - Public classMainactivityextendsActivity { - /**Called when the activity is first created.*/ + @Override - Public voidonCreate (Bundle savedinstancestate) { + Super. OnCreate (savedinstancestate); A Setcontentview (r.layout.main); atImageView imageView2 =(ImageView) Findviewbyid (R.id.picture_qian); - -Bitmap BMP =( (bitmapdrawable) getresources (). Getdrawable ( - r.drawable.horse)). Getbitmap (); - - Imageview2.setimagebitmap (Createreflectedimage (BMP)); in } - to Public StaticBitmap createreflectedimage (Bitmap originalimage) { + - Final intReflectiongap = 4; the * intwidth =originalimage.getwidth (); $ intHeight =originalimage.getheight ();Panax Notoginseng -Matrix Matrix =NewMatrix (); theMatrix.prescale (1,-1); + ABitmap reflectionimage = Bitmap.createbitmap (originalimage, 0, theHEIGHT/2, Width, height/2, matrix,false); + -Bitmap bitmapwithreflection =bitmap.createbitmap (width, $(Height + HEIGHT/2), config.argb_8888); $ -Canvas Canvas =NewCanvas (bitmapwithreflection); - theCanvas.drawbitmap (originalimage, 0, 0,NULL); - WuyiPaint Defaultpaint =NewPaint (); theCanvas.drawrect (0, height, width, height +Reflectiongap, defaultpaint); - WuCanvas.drawbitmap (reflectionimage, 0, height + reflectiongap,NULL); - AboutPaint paint =NewPaint (); $LinearGradient shader =NewLinearGradient (0, -Originalimage.getheight (), 0, Bitmapwithreflection.getheight () -+ Reflectiongap, 0X70FFFFFF, 0X00FFFFFF, - tilemode.mirror); A + Paint.setshader (shader); the -Paint.setxfermode (NewPorterduffxfermode (mode.dst_in)); $ theCanvas.drawrect (0, height, width, bitmapwithreflection.getheight () the+reflectiongap, paint); the the returnbitmapwithreflection; - } in}