DemoÏÂÔØ£ºGalleryFlow
¾ßÌåÏÂÔØÄ¿Â¼ÔÚ /2013Äê×ÊÁÏ/4ÔÂ/22ÈÕ/Android Gallery 3DЧ¹û

ÆäʵʵÏÖÕâ¸öЧ¹ûºÜ¼òµ¥£¬ÏÂÃæ×÷Ò»¸ö¼òµ¥µÄ½éÉÜ
Ò»£¬´´½¨µ¹Ó°Ð§¹û
Õâ¸ö»ù±¾Ë¼Â·ÊÇ£º
1£¬´´½¨Ò»¸öԴͼһÑùµÄͼ£¬ÀûÓÃmartrix½«Í¼Æ¬Ðýת180¶È¡£Õâ¸öµ¹Ó°Í¼µÄ¸ßÊÇԴͼµÄÒ»°ë¡£
Matrix matrix = new Matrix();
// 1±íʾ·Å´ó±ÈÀý£¬²»·Å´óÒ²²»ËõС¡£
// -1±íʾÔÚyÖáÉÏÏà·´£¬¼´Ðýת180¶È¡£
matrix.preScale(1, -1);
Bitmap reflectionBitmap = Bitmap.createBitmap(
srcBitmap,
0,
srcBitmap.getHeight() / 2, // topΪԴͼµÄÒ»°ë
srcBitmap.getWidth(), // ¿í¶ÈÓëԴͼһÑù
srcBitmap.getHeight() / 2, // ¸ß¶ÈÓëԴͼµÄÒ»°ë
matrix,
false);
2£¬´´½¨Ò»¸ö×îÖÕЧ¹ûµÄͼ£¬¼´Ô´Í¼ + ¼ä϶ + µ¹Ó°¡£
final int REFLECTION_GAP = 5;
Bitmap bitmapWithReflection = Bitmap.createBitmap(
reflectionWidth,
srcHeight + reflectionHeight + REFLECTION_GAP,
Config.ARGB_8888);
3£¬ÒÀ´Î½«Ô´Í¼¡¢µ¹Ó°Í¼»æÖÆÔÚ×îÖÕµÄbitmapÉÏÃæ¡£
// Prepare the canvas to draw stuff.
Canvas canvas = new Canvas(bitmapWithReflection);
// Draw the original bitmap.
canvas.drawBitmap(srcBitmap, 0, 0, null);
// Draw the reflection bitmap.
canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
4£¬´´½¨LinearGradient£¬´Ó¶ø¸ø¶¨Ò»¸öÓÉÉϵ½ÏµĽ¥±äÉ«¡£
Paint paint = new Paint();
paint.setAntiAlias(true);
LinearGradient shader = new LinearGradient(
0,
srcHeight,
0,
bitmapWithReflection.getHeight() + REFLECTION_GAP,
0x70FFFFFF,
0x00FFFFFF,
TileMode.MIRROR);
paint.setShader(shader);
paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
// Draw the linear shader.
canvas.drawRect(
0,
srcHeight,
srcWidth,
bitmapWithReflection.getHeight() + REFLECTION_GAP,
paint);